Skip to content

noop import: stream the unzip to disk - #1051

Open
abdulsaheel wants to merge 1 commit into
mainfrom
fix/import-fixes
Open

abdulsaheel wants to merge 1 commit into
mainfrom
fix/import-fixes

Conversation

@abdulsaheel

@abdulsaheel abdulsaheel commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

fixes #1042

the noop unzip held the whole backup in memory. _inflateMember now streams the raw deflate straight to the file, crc check after it is unchanged. falls back to the old path for encrypted/unknown-method members.

touches the same function as #1032. no memory test: peak rss can't be asserted in flutter test, existing import tests cover the stale-size and bad-crc cases.

Summary by CodeRabbit

  • Bug Fixes
    • Improved archive imports for stored and deflated ZIP files, with fallback handling for encrypted, unsupported, or malformed entries.

@sourcery-ai

sourcery-ai Bot commented Dec 3, 2026

Copy link
Copy Markdown

Sorry @abdulsaheel, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 19 hours and 27 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The import path now streams unencrypted ZIP members with stored or deflate compression directly to disk. It validates the local header and uses raw zlib decoding for deflate. Encrypted members, unsupported compression methods, and invalid local headers use the existing writeContent fallback.

Changes: ZIP member streaming

Layer / File(s) Summary
Stream supported ZIP members
lib/import/import_container.dart
_inflateMember locates the indexed member and its metadata. It streams supported members to disk, uses raw zlib decoding for deflate, and retains writeContent as a fallback. The imports distinguish the dart:io decoder from the archive package decoder.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant InflateMember as _inflateMember
  participant Archive
  participant ZIPFile as ZIP file
  participant ZLibDecoder
  participant OutputFileStream
  participant WriteContent as ArchiveFile.writeContent
  InflateMember->>Archive: Decode archive and select indexed member
  Archive-->>InflateMember: Return member metadata
  alt Valid unencrypted deflate member
    InflateMember->>ZIPFile: Read compressed byte range
    ZIPFile->>ZLibDecoder: Send compressed bytes
    ZLibDecoder->>OutputFileStream: Write decoded chunks
  else Valid unencrypted stored member
    InflateMember->>ZIPFile: Read stored byte range
    ZIPFile->>OutputFileStream: Write member chunks
  else Encrypted, unsupported, or invalid local header
    InflateMember->>WriteContent: Use existing extraction fallback
  end
Loading

Possibly related issues

  • Issue 1031: The PR streams extracted data to disk, addressing the memory aspect of large backup imports. The change does not establish that the reported 2 GB extraction limit is removed.
Merge Risk: Minimal · up to 00ec2

This change streams supported backup members to disk during import, which lowers peak memory use for large backups. The supplied evidence shows no concrete regression, and the fallback path covers the unsupported cases. Merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "noop import: stream the unzip to disk" matches the main change. The raw summary and PR objectives both say _inflateMember now streams unencrypted stored or deflated members directly to di…
Linked Issues check Passed [#1042] The issue asks to stop holding the inflated NOOP database in memory during import. The diff in lib/import/import_container.dart changes _inflateMember. For stored (method 0) or deflated (met…
Out of Scope Changes check Passed The whole-PR diff against the merge base changes one file, lib/import/import_container.dart. The changes are: a dart:io as io show ZLibDecoder import with hide ZLibDecoder on the archive import, w…
Full details: Title check

Explanation

The title "noop import: stream the unzip to disk" matches the main change. The raw summary and PR objectives both say _inflateMember now streams unencrypted stored or deflated members directly to disk instead of holding the backup in memory. The title names the import path and the streaming approach. It is specific and concise. It does not mention the fallback path, but that is a secondary detail.

Full details: Linked Issues check

Explanation

[#1042] The issue asks to stop holding the inflated NOOP database in memory during import. The diff in lib/import/import_container.dart changes _inflateMember. For stored (method 0) or deflated (method 8) members without the encryption flag, it reads the 30-byte local header, computes the data start offset, and streams the member through File(zipPath).openRead(start, start + compressedSize). For method 8 it applies ZLibDecoder(raw: true), then pipes the output to destPath. This matches the prototype approach in the issue. No size cap is applied, so the stale-size case is not rejected by the new path. Encrypted members, unknown compression methods, and invalid local headers fall back to the original OutputFileStream and writeContent path. The issue requires the stale-size behavior and bad-CRC rejection to be preserved. The diff does not change the caller's CRC check, and the PR states that the existing tests for these cases still apply. Those tests were not re-run in this review. The issue prototype computes CRC while streaming. This PR does not, so the CRC check still runs after extraction. This is a design difference, not a missing requirement. Peak memory was not measured; the issue reports prototype measurements only, and no app-level memory verification is required by the coding objectives.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base changes one file, lib/import/import_container.dart. The changes are: a dart:io as io show ZLibDecoder import with hide ZLibDecoder on the archive import, which avoids a name conflict for the raw decoder; the new streaming branch in _inflateMember; and the existing fallback to writeContent. All changes support the streaming objective in #1042. The PR adds no unrelated refactoring or behavior changes. The PR description notes that it touches the same function as #1032. That overlap is not a scope issue for this review.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between fc6115e and 00ec2d3.

Files selected for processing: 1

  • lib/import/import_container.dart

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Large .noopbak import holds the whole database in memory while unzipping (archive 4.0.9)

1 participant