Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for strip option #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ module.exports = function (zipPath, opts, cb) {
opts.onEntry(entry)
}

var dest = path.join(opts.dir, entry.fileName)
var strip = opts.strip || 0
var filenameParts = entry.fileName.split('/')
filenameParts = filenameParts.slice(Math.min(strip, filenameParts.length - 1))
var destParts = [opts.dir].concat(filenameParts)
var dest = path.join.apply(path, destParts)

// convert external file attr int into a fs stat mode int
var mode = (entry.externalFileAttributes >> 16) & 0xFFFF
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extract(source, {dir: target}, function (err) {
- `defaultDirMode` - integer - Directory Mode (permissions) will default to `493` (octal `0755` in integer)
- `defaultFileMode` - integer - File Mode (permissions) will default to `420` (octal `0644` in integer)
- `onEntry` - function - if present, will be called with every entry from the zip file. forwarded from the `entry` event from yauzl.
- `strip` - integer - number of leading directory components to remove from extracted files.

Default modes are only used if no permissions are set in the zip file.

Expand Down