diff options
Diffstat (limited to 'deps/npm/node_modules/pacote/node_modules/tar-fs')
29 files changed, 1349 insertions, 0 deletions
diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/.npmignore b/deps/npm/node_modules/pacote/node_modules/tar-fs/.npmignore new file mode 100644 index 0000000000..118a1375d0 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/.npmignore @@ -0,0 +1,2 @@ +node_modules +test/fixtures/copy diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/.travis.yml b/deps/npm/node_modules/pacote/node_modules/tar-fs/.travis.yml new file mode 100644 index 0000000000..6e5919de39 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - "0.10" diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/LICENSE b/deps/npm/node_modules/pacote/node_modules/tar-fs/LICENSE new file mode 100644 index 0000000000..757562ec59 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Mathias Buus + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE.
\ No newline at end of file diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/README.md b/deps/npm/node_modules/pacote/node_modules/tar-fs/README.md new file mode 100644 index 0000000000..6cc3b077a5 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/README.md @@ -0,0 +1,143 @@ +# tar-fs + +filesystem bindings for [tar-stream](https://github.com/mafintosh/tar-stream). + +``` +npm install tar-fs +``` + +[![build status](https://secure.travis-ci.org/mafintosh/tar-fs.png)](http://travis-ci.org/mafintosh/tar-fs) + +## Usage + +tar-fs allows you to pack directories into tarballs and extract tarballs into directories. + +It doesn't gunzip for you, so if you want to extract a `.tar.gz` with this you'll need to use something like [gunzip-maybe](https://github.com/mafintosh/gunzip-maybe) in addition to this. + +``` js +var tar = require('tar-fs') +var fs = require('fs') + +// packing a directory +tar.pack('./my-directory').pipe(fs.createWriteStream('my-tarball.tar')) + +// extracting a directory +fs.createReadStream('my-other-tarball.tar').pipe(tar.extract('./my-other-directory')) +``` + +To ignore various files when packing or extracting add a ignore function to the options. `ignore` +is also an alias for `filter`. Additionally you get `header` if you use ignore while extracting. +That way you could also filter by metadata. + +``` js +var pack = tar.pack('./my-directory', { + ignore: function(name) { + return path.extname(name) === '.bin' // ignore .bin files when packing + } +}) + +var extract = tar.extract('./my-other-directory', { + ignore: function(name) { + return path.extname(name) === '.bin' // ignore .bin files inside the tarball when extracing + } +}) + +var extractFilesDirs = tar.extract('./my-other-other-directory', { + ignore: function(_, header) { + // pass files & directories, ignore e.g. symlinks + return header.type !== 'file' && header.type !== 'directory' + } +}) +``` + +You can also specify which entries to pack using the `entries` option + +```js +var pack = tar.pack('./my-directory', { + entries: ['file1', 'subdir/file2'] // only the specific entries will be packed +}) +``` + +If you want to modify the headers when packing/extracting add a map function to the options + +``` js +var pack = tar.pack('./my-directory', { + map: function(header) { + header.name = 'prefixed/'+header.name + return header + } +}) + +var extract = tar.extract('./my-directory', { + map: function(header) { + header.name = 'another-prefix/'+header.name + return header + } +}) +``` + +Similarly you can use `mapStream` incase you wanna modify the input/output file streams + +``` js +var pack = tar.pack('./my-directory', { + mapStream: function(fileStream, header) { + if (path.extname(header.name) === '.js') { + return fileStream.pipe(someTransform) + } + return fileStream; + } +}) + +var extract = tar.extract('./my-directory', { + mapStream: function(fileStream, header) { + if (path.extname(header.name) === '.js') { + return fileStream.pipe(someTransform) + } + return fileStream; + } +}) +``` + +Set `options.fmode` and `options.dmode` to ensure that files/directories extracted have the corresponding modes + +``` js +var extract = tar.extract('./my-directory', { + dmode: parseInt(555, 8), // all dirs should be readable + fmode: parseInt(444, 8) // all files should be readable +}) +``` + +It can be useful to use `dmode` and `fmode` if you are packing/unpacking tarballs between *nix/windows to ensure that all files/directories unpacked are readable. + +Alternatively you can set `options.readable` and/or `options.writable` to set the dmode and fmode to readable/writable. + +``` js +var extract = tar.extract('./my-directory', { + readable: true, // all dirs and files should be readable + writable: true, // all dirs and files should be writable +}) +``` + +Set `options.strict` to `false` if you want to ignore errors due to unsupported entry types (like device files) + +To dereference symlinks (pack the contents of the symlink instead of the link itself) set `options.dereference` to `true`. + +## Copy a directory + +Copying a directory with permissions and mtime intact is as simple as + +``` js +tar.pack('source-directory').pipe(tar.extract('dest-directory')) +``` + +## Performance + +Packing and extracting a 6.1 GB with 2496 directories and 2398 files yields the following results on my Macbook Air. +[See the benchmark here](https://gist.github.com/mafintosh/8102201) + +* tar-fs: 34.261 ms +* [node-tar](https://github.com/isaacs/node-tar): 366.123 ms (or 10x slower) + +## License + +MIT diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/index.js b/deps/npm/node_modules/pacote/node_modules/tar-fs/index.js new file mode 100644 index 0000000000..4bb7637cbe --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/index.js @@ -0,0 +1,323 @@ +var chownr = require('chownr') +var tar = require('tar-stream') +var pump = require('pump') +var mkdirp = require('mkdirp') +var fs = require('fs') +var path = require('path') +var os = require('os') + +var win32 = os.platform() === 'win32' + +var noop = function () {} + +var echo = function (name) { + return name +} + +var normalize = !win32 ? echo : function (name) { + return name.replace(/\\/g, '/').replace(/:/g, '_') +} + +var statAll = function (fs, stat, cwd, ignore, entries, sort) { + var queue = entries || ['.'] + + return function loop (callback) { + if (!queue.length) return callback() + var next = queue.shift() + var nextAbs = path.join(cwd, next) + + stat(nextAbs, function (err, stat) { + if (err) return callback(err) + + if (!stat.isDirectory()) return callback(null, next, stat) + + fs.readdir(nextAbs, function (err, files) { + if (err) return callback(err) + + if (sort) files.sort() + for (var i = 0; i < files.length; i++) { + if (!ignore(path.join(cwd, next, files[i]))) queue.push(path.join(next, files[i])) + } + + callback(null, next, stat) + }) + }) + } +} + +var strip = function (map, level) { + return function (header) { + header.name = header.name.split('/').slice(level).join('/') + + var linkname = header.linkname + if (linkname && (header.type === 'link' || path.isAbsolute(linkname))) { + header.linkname = linkname.split('/').slice(level).join('/') + } + + return map(header) + } +} + +exports.pack = function (cwd, opts) { + if (!cwd) cwd = '.' + if (!opts) opts = {} + + var xfs = opts.fs || fs + var ignore = opts.ignore || opts.filter || noop + var map = opts.map || noop + var mapStream = opts.mapStream || echo + var statNext = statAll(xfs, opts.dereference ? xfs.stat : xfs.lstat, cwd, ignore, opts.entries, opts.sort) + var strict = opts.strict !== false + var umask = typeof opts.umask === 'number' ? ~opts.umask : ~processUmask() + var dmode = typeof opts.dmode === 'number' ? opts.dmode : 0 + var fmode = typeof opts.fmode === 'number' ? opts.fmode : 0 + var pack = opts.pack || tar.pack() + + if (opts.strip) map = strip(map, opts.strip) + + if (opts.readable) { + dmode |= parseInt(555, 8) + fmode |= parseInt(444, 8) + } + if (opts.writable) { + dmode |= parseInt(333, 8) + fmode |= parseInt(222, 8) + } + + var onsymlink = function (filename, header) { + xfs.readlink(path.join(cwd, filename), function (err, linkname) { + if (err) return pack.destroy(err) + header.linkname = normalize(linkname) + pack.entry(header, onnextentry) + }) + } + + var onstat = function (err, filename, stat) { + if (err) return pack.destroy(err) + if (!filename) return pack.finalize() + + if (stat.isSocket()) return onnextentry() // tar does not support sockets... + + var header = { + name: normalize(filename), + mode: (stat.mode | (stat.isDirectory() ? dmode : fmode)) & umask, + mtime: stat.mtime, + size: stat.size, + type: 'file', + uid: stat.uid, + gid: stat.gid + } + + if (stat.isDirectory()) { + header.size = 0 + header.type = 'directory' + header = map(header) || header + return pack.entry(header, onnextentry) + } + + if (stat.isSymbolicLink()) { + header.size = 0 + header.type = 'symlink' + header = map(header) || header + return onsymlink(filename, header) + } + + // TODO: add fifo etc... + + header = map(header) || header + + if (!stat.isFile()) { + if (strict) return pack.destroy(new Error('unsupported type for ' + filename)) + return onnextentry() + } + + var entry = pack.entry(header, onnextentry) + if (!entry) return + + var rs = mapStream(xfs.createReadStream(path.join(cwd, filename)), header) + + rs.on('error', function (err) { // always forward errors on destroy + entry.destroy(err) + }) + + pump(rs, entry) + } + + var onnextentry = function (err) { + if (err) return pack.destroy(err) + statNext(onstat) + } + + onnextentry() + + return pack +} + +var head = function (list) { + return list.length ? list[list.length - 1] : null +} + +var processGetuid = function () { + return process.getuid ? process.getuid() : -1 +} + +var processUmask = function () { + return process.umask ? process.umask() : 0 +} + +exports.extract = function (cwd, opts) { + if (!cwd) cwd = '.' + if (!opts) opts = {} + + var xfs = opts.fs || fs + var ignore = opts.ignore || opts.filter || noop + var map = opts.map || noop + var mapStream = opts.mapStream || echo + var own = opts.chown !== false && !win32 && processGetuid() === 0 + var extract = opts.extract || tar.extract() + var stack = [] + var now = new Date() + var umask = typeof opts.umask === 'number' ? ~opts.umask : ~processUmask() + var dmode = typeof opts.dmode === 'number' ? opts.dmode : 0 + var fmode = typeof opts.fmode === 'number' ? opts.fmode : 0 + var strict = opts.strict !== false + + if (opts.strip) map = strip(map, opts.strip) + + if (opts.readable) { + dmode |= parseInt(555, 8) + fmode |= parseInt(444, 8) + } + if (opts.writable) { + dmode |= parseInt(333, 8) + fmode |= parseInt(222, 8) + } + + var utimesParent = function (name, cb) { // we just set the mtime on the parent dir again everytime we write an entry + var top + while ((top = head(stack)) && name.slice(0, top[0].length) !== top[0]) stack.pop() + if (!top) return cb() + xfs.utimes(top[0], now, top[1], cb) + } + + var utimes = function (name, header, cb) { + if (opts.utimes === false) return cb() + + if (header.type === 'directory') return xfs.utimes(name, now, header.mtime, cb) + if (header.type === 'symlink') return utimesParent(name, cb) // TODO: how to set mtime on link? + + xfs.utimes(name, now, header.mtime, function (err) { + if (err) return cb(err) + utimesParent(name, cb) + }) + } + + var chperm = function (name, header, cb) { + var link = header.type === 'symlink' + var chmod = link ? xfs.lchmod : xfs.chmod + var chown = link ? xfs.lchown : xfs.chown + + if (!chmod) return cb() + + var mode = (header.mode | (header.type === 'directory' ? dmode : fmode)) & umask + chmod(name, mode, function (err) { + if (err) return cb(err) + if (!own) return cb() + if (!chown) return cb() + chown(name, header.uid, header.gid, cb) + }) + } + + extract.on('entry', function (header, stream, next) { + header = map(header) || header + header.name = normalize(header.name) + var name = path.join(cwd, path.join('/', header.name)) + + if (ignore(name, header)) { + stream.resume() + return next() + } + + var stat = function (err) { + if (err) return next(err) + utimes(name, header, function (err) { + if (err) return next(err) + if (win32) return next() + chperm(name, header, next) + }) + } + + var onsymlink = function () { + if (win32) return next() // skip symlinks on win for now before it can be tested + xfs.unlink(name, function () { + xfs.symlink(header.linkname, name, stat) + }) + } + + var onlink = function () { + if (win32) return next() // skip links on win for now before it can be tested + xfs.unlink(name, function () { + var srcpath = path.resolve(cwd, header.linkname) + + xfs.link(srcpath, name, function (err) { + if (err && err.code === 'EPERM' && opts.hardlinkAsFilesFallback) { + stream = xfs.createReadStream(srcpath) + return onfile() + } + + stat(err) + }) + }) + } + + var onfile = function () { + var ws = xfs.createWriteStream(name) + var rs = mapStream(stream, header) + + ws.on('error', function (err) { // always forward errors on destroy + rs.destroy(err) + }) + + pump(rs, ws, function (err) { + if (err) return next(err) + ws.on('close', stat) + }) + } + + if (header.type === 'directory') { + stack.push([name, header.mtime]) + return mkdirfix(name, { + fs: xfs, own: own, uid: header.uid, gid: header.gid + }, stat) + } + + mkdirfix(path.dirname(name), { + fs: xfs, own: own, uid: header.uid, gid: header.gid + }, function (err) { + if (err) return next(err) + + switch (header.type) { + case 'file': return onfile() + case 'link': return onlink() + case 'symlink': return onsymlink() + } + + if (strict) return next(new Error('unsupported type for ' + name + ' (' + header.type + ')')) + + stream.resume() + next() + }) + }) + + return extract +} + +function mkdirfix (name, opts, cb) { + mkdirp(name, {fs: opts.xfs}, function (err, made) { + if (!err && made && opts.own) { + chownr(made, opts.uid, opts.gid, cb) + } else { + cb(err) + } + }) +} diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/.npmignore b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/.npmignore new file mode 100644 index 0000000000..3c3629e647 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/.npmignore @@ -0,0 +1 @@ +node_modules diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/.travis.yml b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/.travis.yml new file mode 100644 index 0000000000..17f94330e7 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/.travis.yml @@ -0,0 +1,5 @@ +language: node_js +node_js: + - "0.10" + +script: "npm test" diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/LICENSE b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/LICENSE new file mode 100644 index 0000000000..757562ec59 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Mathias Buus + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE.
\ No newline at end of file diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/README.md b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/README.md new file mode 100644 index 0000000000..5029b27d68 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/README.md @@ -0,0 +1,56 @@ +# pump + +pump is a small node module that pipes streams together and destroys all of them if one of them closes. + +``` +npm install pump +``` + +[![build status](http://img.shields.io/travis/mafintosh/pump.svg?style=flat)](http://travis-ci.org/mafintosh/pump) + +## What problem does it solve? + +When using standard `source.pipe(dest)` source will _not_ be destroyed if dest emits close or an error. +You are also not able to provide a callback to tell when then pipe has finished. + +pump does these two things for you + +## Usage + +Simply pass the streams you want to pipe together to pump and add an optional callback + +``` js +var pump = require('pump') +var fs = require('fs') + +var source = fs.createReadStream('/dev/random') +var dest = fs.createWriteStream('/dev/null') + +pump(source, dest, function(err) { + console.log('pipe finished', err) +}) + +setTimeout(function() { + dest.destroy() // when dest is closed pump will destroy source +}, 1000) +``` + +You can use pump to pipe more than two streams together as well + +``` js +var transform = someTransformStream() + +pump(source, transform, anotherTransform, dest, function(err) { + console.log('pipe finished', err) +}) +``` + +If `source`, `transform`, `anotherTransform` or `dest` closes all of them will be destroyed. + +## License + +MIT + +## Related + +`pump` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one. diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/index.js b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/index.js new file mode 100644 index 0000000000..060ce5f4fd --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/index.js @@ -0,0 +1,80 @@ +var once = require('once') +var eos = require('end-of-stream') +var fs = require('fs') // we only need fs to get the ReadStream and WriteStream prototypes + +var noop = function () {} + +var isFn = function (fn) { + return typeof fn === 'function' +} + +var isFS = function (stream) { + if (!fs) return false // browser + return (stream instanceof (fs.ReadStream || noop) || stream instanceof (fs.WriteStream || noop)) && isFn(stream.close) +} + +var isRequest = function (stream) { + return stream.setHeader && isFn(stream.abort) +} + +var destroyer = function (stream, reading, writing, callback) { + callback = once(callback) + + var closed = false + stream.on('close', function () { + closed = true + }) + + eos(stream, {readable: reading, writable: writing}, function (err) { + if (err) return callback(err) + closed = true + callback() + }) + + var destroyed = false + return function (err) { + if (closed) return + if (destroyed) return + destroyed = true + + if (isFS(stream)) return stream.close() // use close for fs streams to avoid fd leaks + if (isRequest(stream)) return stream.abort() // request.destroy just do .end - .abort is what we want + + if (isFn(stream.destroy)) return stream.destroy() + + callback(err || new Error('stream was destroyed')) + } +} + +var call = function (fn) { + fn() +} + +var pipe = function (from, to) { + return from.pipe(to) +} + +var pump = function () { + var streams = Array.prototype.slice.call(arguments) + var callback = isFn(streams[streams.length - 1] || noop) && streams.pop() || noop + + if (Array.isArray(streams[0])) streams = streams[0] + if (streams.length < 2) throw new Error('pump requires two streams per minimum') + + var error + var destroys = streams.map(function (stream, i) { + var reading = i < streams.length - 1 + var writing = i > 0 + return destroyer(stream, reading, writing, function (err) { + if (!error) error = err + if (err) destroys.forEach(call) + if (reading) return + destroys.forEach(call) + callback(error) + }) + }) + + return streams.reduce(pipe) +} + +module.exports = pump diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/node_modules/end-of-stream/LICENSE b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/node_modules/end-of-stream/LICENSE new file mode 100644 index 0000000000..757562ec59 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/node_modules/end-of-stream/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Mathias Buus + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE.
\ No newline at end of file diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/node_modules/end-of-stream/README.md b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/node_modules/end-of-stream/README.md new file mode 100644 index 0000000000..f2560c939d --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/node_modules/end-of-stream/README.md @@ -0,0 +1,52 @@ +# end-of-stream + +A node module that calls a callback when a readable/writable/duplex stream has completed or failed. + + npm install end-of-stream + +## Usage + +Simply pass a stream and a callback to the `eos`. +Both legacy streams, streams2 and stream3 are supported. + +``` js +var eos = require('end-of-stream'); + +eos(readableStream, function(err) { + // this will be set to the stream instance + if (err) return console.log('stream had an error or closed early'); + console.log('stream has ended', this === readableStream); +}); + +eos(writableStream, function(err) { + if (err) return console.log('stream had an error or closed early'); + console.log('stream has finished', this === writableStream); +}); + +eos(duplexStream, function(err) { + if (err) return console.log('stream had an error or closed early'); + console.log('stream has ended and finished', this === duplexStream); +}); + +eos(duplexStream, {readable:false}, function(err) { + if (err) return console.log('stream had an error or closed early'); + console.log('stream has finished but might still be readable'); +}); + +eos(duplexStream, {writable:false}, function(err) { + if (err) return console.log('stream had an error or closed early'); + console.log('stream has ended but might still be writable'); +}); + +eos(readableStream, {error:false}, function(err) { + // do not treat emit('error', err) as a end-of-stream +}); +``` + +## License + +MIT + +## Related + +`end-of-stream` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one. diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/node_modules/end-of-stream/index.js b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/node_modules/end-of-stream/index.js new file mode 100644 index 0000000000..b3a9068634 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/node_modules/end-of-stream/index.js @@ -0,0 +1,83 @@ +var once = require('once'); + +var noop = function() {}; + +var isRequest = function(stream) { + return stream.setHeader && typeof stream.abort === 'function'; +}; + +var isChildProcess = function(stream) { + return stream.stdio && Array.isArray(stream.stdio) && stream.stdio.length === 3 +}; + +var eos = function(stream, opts, callback) { + if (typeof opts === 'function') return eos(stream, null, opts); + if (!opts) opts = {}; + + callback = once(callback || noop); + + var ws = stream._writableState; + var rs = stream._readableState; + var readable = opts.readable || (opts.readable !== false && stream.readable); + var writable = opts.writable || (opts.writable !== false && stream.writable); + + var onlegacyfinish = function() { + if (!stream.writable) onfinish(); + }; + + var onfinish = function() { + writable = false; + if (!readable) callback.call(stream); + }; + + var onend = function() { + readable = false; + if (!writable) callback.call(stream); + }; + + var onexit = function(exitCode) { + callback.call(stream, exitCode ? new Error('exited with error code: ' + exitCode) : null); + }; + + var onclose = function() { + if (readable && !(rs && rs.ended)) return callback.call(stream, new Error('premature close')); + if (writable && !(ws && ws.ended)) return callback.call(stream, new Error('premature close')); + }; + + var onrequest = function() { + stream.req.on('finish', onfinish); + }; + + if (isRequest(stream)) { + stream.on('complete', onfinish); + stream.on('abort', onclose); + if (stream.req) onrequest(); + else stream.on('request', onrequest); + } else if (writable && !ws) { // legacy streams + stream.on('end', onlegacyfinish); + stream.on('close', onlegacyfinish); + } + + if (isChildProcess(stream)) stream.on('exit', onexit); + + stream.on('end', onend); + stream.on('finish', onfinish); + if (opts.error !== false) stream.on('error', callback); + stream.on('close', onclose); + + return function() { + stream.removeListener('complete', onfinish); + stream.removeListener('abort', onclose); + stream.removeListener('request', onrequest); + if (stream.req) stream.req.removeListener('finish', onfinish); + stream.removeListener('end', onlegacyfinish); + stream.removeListener('close', onlegacyfinish); + stream.removeListener('finish', onfinish); + stream.removeListener('exit', onexit); + stream.removeListener('end', onend); + stream.removeListener('error', callback); + stream.removeListener('close', onclose); + }; +}; + +module.exports = eos; diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/node_modules/end-of-stream/package.json b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/node_modules/end-of-stream/package.json new file mode 100644 index 0000000000..28eeea06e2 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/node_modules/end-of-stream/package.json @@ -0,0 +1,66 @@ +{ + "_from": "end-of-stream@^1.1.0", + "_id": "end-of-stream@1.4.0", + "_integrity": "sha1-epDYM+/abPpurA9JSduw+tOmMgY=", + "_location": "/pacote/tar-fs/pump/end-of-stream", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "end-of-stream@^1.1.0", + "name": "end-of-stream", + "escapedName": "end-of-stream", + "rawSpec": "^1.1.0", + "saveSpec": null, + "fetchSpec": "^1.1.0" + }, + "_requiredBy": [ + "/pacote/tar-fs/pump" + ], + "_resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.0.tgz", + "_shasum": "7a90d833efda6cfa6eac0f4949dbb0fad3a63206", + "_shrinkwrap": null, + "_spec": "end-of-stream@^1.1.0", + "_where": "/Users/zkat/Documents/code/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump", + "author": { + "name": "Mathias Buus", + "email": "mathiasbuus@gmail.com" + }, + "bin": null, + "bugs": { + "url": "https://github.com/mafintosh/end-of-stream/issues" + }, + "bundleDependencies": false, + "dependencies": { + "once": "^1.4.0" + }, + "deprecated": false, + "description": "Call a callback when a readable/writable/duplex stream has completed or failed.", + "devDependencies": {}, + "files": [ + "index.js" + ], + "homepage": "https://github.com/mafintosh/end-of-stream", + "keywords": [ + "stream", + "streams", + "callback", + "finish", + "close", + "end", + "wait" + ], + "license": "MIT", + "main": "index.js", + "name": "end-of-stream", + "optionalDependencies": {}, + "peerDependencies": {}, + "repository": { + "type": "git", + "url": "git://github.com/mafintosh/end-of-stream.git" + }, + "scripts": { + "test": "node test.js" + }, + "version": "1.4.0" +} diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/package.json b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/package.json new file mode 100644 index 0000000000..2af973326b --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/package.json @@ -0,0 +1,65 @@ +{ + "_from": "pump@^1.0.0", + "_id": "pump@1.0.2", + "_integrity": "sha1-Oz7mUS+U8OV1U4wXmV+fFpkKXVE=", + "_location": "/pacote/tar-fs/pump", + "_phantomChildren": { + "once": "1.4.0" + }, + "_requested": { + "type": "range", + "registry": true, + "raw": "pump@^1.0.0", + "name": "pump", + "escapedName": "pump", + "rawSpec": "^1.0.0", + "saveSpec": null, + "fetchSpec": "^1.0.0" + }, + "_requiredBy": [ + "/pacote/tar-fs" + ], + "_resolved": "https://registry.npmjs.org/pump/-/pump-1.0.2.tgz", + "_shasum": "3b3ee6512f94f0e575538c17995f9f16990a5d51", + "_shrinkwrap": null, + "_spec": "pump@^1.0.0", + "_where": "/Users/zkat/Documents/code/npm/node_modules/pacote/node_modules/tar-fs", + "author": { + "name": "Mathias Buus Madsen", + "email": "mathiasbuus@gmail.com" + }, + "bin": null, + "browser": { + "fs": false + }, + "bugs": { + "url": "https://github.com/mafintosh/pump/issues" + }, + "bundleDependencies": false, + "dependencies": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + }, + "deprecated": false, + "description": "pipe streams together and close all of them if one of them closes", + "devDependencies": {}, + "homepage": "https://github.com/mafintosh/pump#readme", + "keywords": [ + "streams", + "pipe", + "destroy", + "callback" + ], + "license": "MIT", + "name": "pump", + "optionalDependencies": {}, + "peerDependencies": {}, + "repository": { + "type": "git", + "url": "git://github.com/mafintosh/pump.git" + }, + "scripts": { + "test": "node test.js" + }, + "version": "1.0.2" +} diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/test-browser.js b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/test-browser.js new file mode 100644 index 0000000000..80e852c7dc --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/test-browser.js @@ -0,0 +1,58 @@ +var stream = require('stream') +var pump = require('./index') + +var rs = new stream.Readable() +var ws = new stream.Writable() + +rs._read = function (size) { + this.push(Buffer(size).fill('abc')) +} + +ws._write = function (chunk, encoding, cb) { + setTimeout(function () { + cb() + }, 100) +} + +var toHex = function () { + var reverse = new (require('stream').Transform)() + + reverse._transform = function (chunk, enc, callback) { + reverse.push(chunk.toString('hex')) + callback() + } + + return reverse +} + +var wsClosed = false +var rsClosed = false +var callbackCalled = false + +var check = function () { + if (wsClosed && rsClosed && callbackCalled) console.log('done') +} + +ws.on('finish', function () { + wsClosed = true + check() +}) + +rs.on('end', function () { + rsClosed = true + check() +}) + +pump(rs, toHex(), toHex(), toHex(), ws, function () { + callbackCalled = true + check() +}) + +setTimeout(function () { + rs.push(null) + rs.emit('close') +}, 1000) + +setTimeout(function () { + if (!check()) throw new Error('timeout') +}, 5000) diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/test.js b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/test.js new file mode 100644 index 0000000000..64e772ca5b --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/node_modules/pump/test.js @@ -0,0 +1,46 @@ +var pump = require('./index') + +var rs = require('fs').createReadStream('/dev/random') +var ws = require('fs').createWriteStream('/dev/null') + +var toHex = function () { + var reverse = new (require('stream').Transform)() + + reverse._transform = function (chunk, enc, callback) { + reverse.push(chunk.toString('hex')) + callback() + } + + return reverse +} + +var wsClosed = false +var rsClosed = false +var callbackCalled = false + +var check = function () { + if (wsClosed && rsClosed && callbackCalled) process.exit(0) +} + +ws.on('close', function () { + wsClosed = true + check() +}) + +rs.on('close', function () { + rsClosed = true + check() +}) + +pump(rs, toHex(), toHex(), toHex(), ws, function () { + callbackCalled = true + check() +}) + +setTimeout(function () { + rs.destroy() +}, 1000) + +setTimeout(function () { + throw new Error('timeout') +}, 5000) diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/package.json b/deps/npm/node_modules/pacote/node_modules/tar-fs/package.json new file mode 100644 index 0000000000..2574d083ab --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/package.json @@ -0,0 +1,73 @@ +{ + "_from": "tar-fs@^1.15.1", + "_id": "tar-fs@1.15.2", + "_integrity": "sha1-dh9bMpMsezlGGmDVN/rqDYCEgww=", + "_location": "/pacote/tar-fs", + "_phantomChildren": { + "once": "1.4.0" + }, + "_requested": { + "type": "range", + "registry": true, + "raw": "tar-fs@^1.15.1", + "name": "tar-fs", + "escapedName": "tar-fs", + "rawSpec": "^1.15.1", + "saveSpec": null, + "fetchSpec": "^1.15.1" + }, + "_requiredBy": [ + "/pacote" + ], + "_resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-1.15.2.tgz", + "_shasum": "761f5b32932c7b39461a60d537faea0d8084830c", + "_shrinkwrap": null, + "_spec": "tar-fs@^1.15.1", + "_where": "/Users/zkat/Documents/code/npm/node_modules/pacote", + "author": { + "name": "Mathias Buus" + }, + "bin": null, + "bugs": { + "url": "https://github.com/mafintosh/tar-fs/issues" + }, + "bundleDependencies": false, + "dependencies": { + "chownr": "^1.0.1", + "mkdirp": "^0.5.1", + "pump": "^1.0.0", + "tar-stream": "^1.1.2" + }, + "deprecated": false, + "description": "filesystem bindings for tar-stream", + "devDependencies": { + "rimraf": "^2.2.8", + "standard": "^4.5.4", + "tape": "^3.0.0" + }, + "directories": { + "test": "test" + }, + "homepage": "https://github.com/mafintosh/tar-fs", + "keywords": [ + "tar", + "fs", + "file", + "tarball", + "directory", + "stream" + ], + "license": "MIT", + "main": "index.js", + "name": "tar-fs", + "optionalDependencies": {}, + "peerDependencies": {}, + "repository": { + "type": "git", + "url": "git+https://github.com/mafintosh/tar-fs.git" + }, + "scripts": { + "test": "standard && tape test/index.js" + }, + "version": "1.15.2" +} diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/a/hello.txt b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/a/hello.txt new file mode 100644 index 0000000000..3b18e512db --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/a/hello.txt @@ -0,0 +1 @@ +hello world diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/b/a/test.txt b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/b/a/test.txt new file mode 100644 index 0000000000..9daeafb986 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/b/a/test.txt @@ -0,0 +1 @@ +test diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/c/.npmignore b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/c/.npmignore new file mode 100644 index 0000000000..2b2328d77c --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/c/.npmignore @@ -0,0 +1 @@ +link diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/d/file1 b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/d/file1 new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/d/file1 diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/d/file2 b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/d/file2 new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/d/file2 diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/d/sub-dir/file5 b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/d/sub-dir/file5 new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/d/sub-dir/file5 diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/d/sub-files/file3 b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/d/sub-files/file3 new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/d/sub-files/file3 diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/d/sub-files/file4 b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/d/sub-files/file4 new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/d/sub-files/file4 diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/e/directory/.ignore b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/e/directory/.ignore new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/e/directory/.ignore diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/e/file b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/e/file new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/fixtures/e/file diff --git a/deps/npm/node_modules/pacote/node_modules/tar-fs/test/index.js b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/index.js new file mode 100644 index 0000000000..01ca87f2a8 --- /dev/null +++ b/deps/npm/node_modules/pacote/node_modules/tar-fs/test/index.js @@ -0,0 +1,227 @@ +var test = require('tape') +var rimraf = require('rimraf') +var tar = require('../index') +var path = require('path') +var fs = require('fs') +var os = require('os') + +var win32 = os.platform() === 'win32' + +var mtime = function (st) { + return Math.floor(st.mtime.getTime() / 1000) +} + +test('copy a -> copy/a', function (t) { + t.plan(5) + + var a = path.join(__dirname, 'fixtures', 'a') + var b = path.join(__dirname, 'fixtures', 'copy', 'a') + + rimraf.sync(b) + tar.pack(a) + .pipe(tar.extract(b)) + .on('finish', function () { + var files = fs.readdirSync(b) + t.same(files.length, 1) + t.same(files[0], 'hello.txt') + var fileB = path.join(b, files[0]) + var fileA = path.join(a, files[0]) + t.same(fs.readFileSync(fileB, 'utf-8'), fs.readFileSync(fileA, 'utf-8')) + t.same(fs.statSync(fileB).mode, fs.statSync(fileA).mode) + t.same(mtime(fs.statSync(fileB)), mtime(fs.statSync(fileA))) + }) +}) + +test('copy b -> copy/b', function (t) { + t.plan(8) + + var a = path.join(__dirname, 'fixtures', 'b') + var b = path.join(__dirname, 'fixtures', 'copy', 'b') + + rimraf.sync(b) + tar.pack(a) + .pipe(tar.extract(b)) + .on('finish', function () { + var files = fs.readdirSync(b) + t.same(files.length, 1) + t.same(files[0], 'a') + var dirB = path.join(b, files[0]) + var dirA = path.join(a, files[0]) + t.same(fs.statSync(dirB).mode, fs.statSync(dirA).mode) + t.same(mtime(fs.statSync(dirB)), mtime(fs.statSync(dirA))) + t.ok(fs.statSync(dirB).isDirectory()) + var fileB = path.join(dirB, 'test.txt') + var fileA = path.join(dirA, 'test.txt') + t.same(fs.readFileSync(fileB, 'utf-8'), fs.readFileSync(fileA, 'utf-8')) + t.same(fs.statSync(fileB).mode, fs.statSync(fileA).mode) + t.same(mtime(fs.statSync(fileB)), mtime(fs.statSync(fileA))) + }) +}) + +test('symlink', function (t) { + if (win32) { // no symlink support on win32 currently. TODO: test if this can be enabled somehow + t.plan(1) + t.ok(true) + return + } + + t.plan(5) + + var a = path.join(__dirname, 'fixtures', 'c') + + rimraf.sync(path.join(a, 'link')) + fs.symlinkSync('.gitignore', path.join(a, 'link')) + + var b = path.join(__dirname, 'fixtures', 'copy', 'c') + + rimraf.sync(b) + tar.pack(a) + .pipe(tar.extract(b)) + .on('finish', function () { + var files = fs.readdirSync(b).sort() + t.same(files.length, 2) + t.same(files[0], '.gitignore') + t.same(files[1], 'link') + + var linkA = path.join(a, 'link') + var linkB = path.join(b, 'link') + + t.same(mtime(fs.lstatSync(linkB)), mtime(fs.lstatSync(linkA))) + t.same(fs.readlinkSync(linkB), fs.readlinkSync(linkA)) + }) +}) + +test('follow symlinks', function (t) { + if (win32) { // no symlink support on win32 currently. TODO: test if this can be enabled somehow + t.plan(1) + t.ok(true) + return + } + + t.plan(5) + + var a = path.join(__dirname, 'fixtures', 'c') + + rimraf.sync(path.join(a, 'link')) + fs.symlinkSync('.gitignore', path.join(a, 'link')) + + var b = path.join(__dirname, 'fixtures', 'copy', 'c-dereference') + + rimraf.sync(b) + tar.pack(a, {dereference: true}) + .pipe(tar.extract(b)) + .on('finish', function () { + var files = fs.readdirSync(b).sort() + t.same(files.length, 2) + t.same(files[0], '.gitignore') + t.same(files[1], 'link') + + var file1 = path.join(b, '.gitignore') + var file2 = path.join(b, 'link') + + t.same(mtime(fs.lstatSync(file1)), mtime(fs.lstatSync(file2))) + t.same(fs.readFileSync(file1), fs.readFileSync(file2)) + }) +}) + +test('strip', function (t) { + t.plan(2) + + var a = path.join(__dirname, 'fixtures', 'b') + var b = path.join(__dirname, 'fixtures', 'copy', 'b-strip') + + rimraf.sync(b) + + tar.pack(a) + .pipe(tar.extract(b, {strip: 1})) + .on('finish', function () { + var files = fs.readdirSync(b).sort() + t.same(files.length, 1) + t.same(files[0], 'test.txt') + }) +}) + +test('strip + map', function (t) { + t.plan(2) + + var a = path.join(__dirname, 'fixtures', 'b') + var b = path.join(__dirname, 'fixtures', 'copy', 'b-strip') + + rimraf.sync(b) + + var uppercase = function (header) { + header.name = header.name.toUpperCase() + return header + } + + tar.pack(a) + .pipe(tar.extract(b, {strip: 1, map: uppercase})) + .on('finish', function () { + var files = fs.readdirSync(b).sort() + t.same(files.length, 1) + t.same(files[0], 'TEST.TXT') + }) +}) + +test('map + dir + permissions', function (t) { + t.plan(win32 ? 1 : 2) // skip chmod test, it's not working like unix + + var a = path.join(__dirname, 'fixtures', 'b') + var b = path.join(__dirname, 'fixtures', 'copy', 'a-perms') + + rimraf.sync(b) + + var aWithMode = function (header) { + if (header.name === 'a') { + header.mode = parseInt(700, 8) + } + return header + } + + tar.pack(a) + .pipe(tar.extract(b, {map: aWithMode})) + .on('finish', function () { + var files = fs.readdirSync(b).sort() + var stat = fs.statSync(path.join(b, 'a')) + t.same(files.length, 1) + if (!win32) { + t.same(stat.mode & parseInt(777, 8), parseInt(700, 8)) + } + }) +}) + +test('specific entries', function (t) { + t.plan(6) + + var a = path.join(__dirname, 'fixtures', 'd') + var b = path.join(__dirname, 'fixtures', 'copy', 'd-entries') + + var entries = [ 'file1', 'sub-files/file3', 'sub-dir' ] + + rimraf.sync(b) + tar.pack(a, {entries: entries}) + .pipe(tar.extract(b)) + .on('finish', function () { + var files = fs.readdirSync(b) + t.same(files.length, 3) + t.notSame(files.indexOf('file1'), -1) + t.notSame(files.indexOf('sub-files'), -1) + t.notSame(files.indexOf('sub-dir'), -1) + var subFiles = fs.readdirSync(path.join(b, 'sub-files')) + t.same(subFiles, ['file3']) + var subDir = fs.readdirSync(path.join(b, 'sub-dir')) + t.same(subDir, ['file5']) + }) +}) + +test('check type while mapping header on packing', function (t) { + t.plan(3) + + var e = path.join(__dirname, 'fixtures', 'e') + + var checkHeaderType = function (header) { + if (header.name.indexOf('.') === -1) t.same(header.type, header.name) + } + + tar.pack(e, { map: checkHeaderType }) +}) |