compressing icon indicating copy to clipboard operation
compressing copied to clipboard

WIP: feat: support strip for all archive

Open bytemain opened this issue 1 month ago • 2 comments

Previous, only zip stream support strip option, now support for all uncompress stream

todo:

  • [ ] add test for tgz

Summary by CodeRabbit

Release Notes

  • New Features

    • Added strip option to uncompress operations, allowing removal of leading path components from extracted file structures.
  • Tests

    • Expanded test coverage to validate strip functionality across multiple archive formats, ensuring correct extraction behavior.

bytemain avatar Nov 17 '25 06:11 bytemain

Walkthrough

This pull request implements file path stripping functionality during decompression operations. The core change adds support for a strip option in makeUncompressFn that normalizes extracted file paths by removing leading directory components, with corresponding test coverage for tar and tgz formats.

Changes

Cohort / File(s) Summary
Core strip functionality
lib/utils.js
Extracts strip option from opts (default 0), removes it before passing to UncompressStream, and uses stripFileName() to normalize destination paths based on the strip level.
Assertion improvement
test/zip/index.test.js
Updates file mode assertion from strict equality check to assert.equal() with descriptive message for better test output.
Strip option test coverage
test/tar/index.test.js, test/tgz/index.test.js
Adds new test cases for uncompress() with strip: 1 and strip: 2 options, validating path normalization behavior and resulting directory structure for both tar and tgz formats.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant makeUncompressFn
    participant stripFileName
    participant UncompressStream
    participant FS as File System

    User->>makeUncompressFn: uncompress(source, dest, {strip: 1})
    makeUncompressFn->>makeUncompressFn: derive strip from opts.strip
    makeUncompressFn->>makeUncompressFn: remove strip from opts
    makeUncompressFn->>UncompressStream: create stream with cleaned opts
    UncompressStream->>UncompressStream: emit entry events
    makeUncompressFn->>stripFileName: normalize path (strip=1, header.name)
    stripFileName-->>makeUncompressFn: return normalized path
    makeUncompressFn->>FS: write file to normalized destination
    FS-->>User: extraction complete with paths stripped

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Core implementation (lib/utils.js): Requires understanding the stripFileName() function behavior and how it interacts with the existing uncompression flow
  • New test cases (test files): Multiple similar test cases added across tar and tgz formats, each requiring verification of expected behavior and assertions; consistency check across formats
  • Assertion change (test/zip/index.test.js): Straightforward style improvement with minimal risk

Possibly related PRs

  • node-modules/compressing#113: Both PRs modify makeUncompressFn in lib/utils.js with different refactoring approaches (native fs/pipeline vs. strip handling and path normalization).

Suggested reviewers

  • fengmk2

Poem

🐰 Hopping through archives with stripping delight, Nested paths shortened, extraction feels right! Tar, tgz, zip files now skip what's not needed, The strip option blooms where recursion proceeded. 🎀

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'WIP: feat: support strip for all archive' is partially related to the changeset. It correctly identifies the main feature being added (strip support for all archive types), but contains 'WIP' prefix and has a grammatical issue ('archive' should be 'archives'). The core message is clear and specific enough.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Nov 17 '25 06:11 coderabbitai[bot]

似乎 windows 上的 dircompare 是不稳定的

bytemain avatar Nov 17 '25 07:11 bytemain