Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ advanced use cases, such as re-using caches between runs.
Defaults to 16 MB.
- `umask` Filter the modes of entries like `process.umask()`.
- `dmode` Default mode for directories
- `fflag` Default flag for files
- `fmode` Default mode for files
- `dirCache` A Map object of which directories exist.
- `maxMetaEntrySize` The maximum size of meta entries that is
Expand Down Expand Up @@ -599,6 +600,7 @@ Most unpack errors will cause a `warn` event to be emitted. If the
any warnings encountered.
- `umask` Filter the modes of entries like `process.umask()`.
- `dmode` Default mode for directories
- `fflag` Default flag for files
- `fmode` Default mode for files
- `dirCache` A Map object of which directories exist.
- `maxMetaEntrySize` The maximum size of meta entries that is
Expand Down
17 changes: 17 additions & 0 deletions benchmarks/extract/node-tar-fmap-async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const cwd = __dirname + '/cwd'
const rimraf = require('rimraf')
rimraf.sync(cwd)
require('mkdirp').sync(cwd)
process.on('exit', _ => rimraf.sync(cwd))
const path = require('path')
const file = process.argv[2] || path.resolve(__dirname, '../npm.tar')
const fs = require('fs')
const { O_CREAT, O_TRUNC, O_WRONLY, UV_FS_O_FILEMAP = 0 } = fs.constants

const tar = require('../..')
const timer = require('../timer.js')()
tar.x({
fflag: (UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY),
file: file,
cwd: cwd
}).then(timer)
19 changes: 19 additions & 0 deletions benchmarks/extract/node-tar-fmap-sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const cwd = __dirname + '/cwd'
const rimraf = require('rimraf')
rimraf.sync(cwd)
require('mkdirp').sync(cwd)
process.on('exit', _ => rimraf.sync(cwd))
const path = require('path')
const file = process.argv[2] || path.resolve(__dirname, '../npm.tar')
const fs = require('fs')
const { O_CREAT, O_TRUNC, O_WRONLY, UV_FS_O_FILEMAP = 0 } = fs.constants

const tar = require('../..')
const timer = require('../timer.js')()
tar.x({
fflag: (UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY),
file: file,
sync: true,
cwd: cwd
})
timer()
4 changes: 3 additions & 1 deletion lib/unpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class Unpack extends Parser {
this.umask = typeof opt.umask === 'number' ? opt.umask : this.processUmask
// default mode for dirs created as parents
this.dmode = opt.dmode || (0o0777 & (~this.umask))
this.fflag = opt.fflag || 'w'
this.fmode = opt.fmode || (0o0666 & (~this.umask))
this.on('entry', entry => this[ONENTRY](entry))
}
Expand Down Expand Up @@ -294,6 +295,7 @@ class Unpack extends Parser {
[FILE] (entry) {
const mode = entry.mode & 0o7777 || this.fmode
const stream = new fsm.WriteStream(entry.absolute, {
flags: this.fflag,
mode: mode,
autoClose: false
})
Expand Down Expand Up @@ -515,7 +517,7 @@ class UnpackSync extends Unpack {
let stream
let fd
try {
fd = fs.openSync(entry.absolute, 'w', mode)
fd = fs.openSync(entry.absolute, this.fflag, mode)
} catch (er) {
return oner(er)
}
Expand Down
17 changes: 15 additions & 2 deletions test/unpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const makeTar = require('./make-tar.js')
const Header = require('../lib/header.js')
const z = require('minizlib')
const fs = require('fs')
const { O_CREAT, O_TRUNC, O_WRONLY, UV_FS_O_FILEMAP = 0 } = fs.constants
const path = require('path')
const fixtures = path.resolve(__dirname, 'fixtures')
const files = path.resolve(fixtures, 'files')
Expand Down Expand Up @@ -100,7 +101,7 @@ t.test('basic file unpack tests', t => {
t.plan(2)

t.test('async unpack', t => {
t.plan(2)
t.plan(3)
t.test('strict', t => {
const unpack = new Unpack({ cwd: linkdir, strict: true })
fs.createReadStream(tf).pipe(unpack)
Expand All @@ -111,10 +112,16 @@ t.test('basic file unpack tests', t => {
fs.createReadStream(tf).pipe(unpack)
eos(unpack, _ => check(t))
})
t.test('fmap', t => {
const mw = UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY
const unpack = new Unpack({ cwd: linkdir, fflag: mw })
fs.createReadStream(tf).pipe(unpack)
eos(unpack, _ => check(t))
})
})

t.test('sync unpack', t => {
t.plan(2)
t.plan(3)
t.test('strict', t => {
const unpack = new UnpackSync({ cwd: linkdir })
unpack.end(fs.readFileSync(tf))
Expand All @@ -125,6 +132,12 @@ t.test('basic file unpack tests', t => {
unpack.end(fs.readFileSync(tf))
check(t)
})
t.test('fmap', t => {
const mw = UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY
const unpack = new UnpackSync({ cwd: linkdir, fflag: mw })
unpack.end(fs.readFileSync(tf))
check(t)
})
})
})
})
Expand Down