tar-stream
Advanced tools
Comparing version 0.1.2 to 0.2.0
@@ -31,2 +31,3 @@ var stream = require('stream'); | ||
this._locked = false; | ||
this._destroyed = false; | ||
@@ -42,3 +43,6 @@ var self = this; | ||
self._locked = false; | ||
if (err) return self.emit('error', err); | ||
if (err) { | ||
self.emit('error', err); | ||
return self.destroy(); | ||
} | ||
if (!self._stream) oncontinue(); | ||
@@ -70,9 +74,11 @@ }; | ||
} | ||
self._locked = true; | ||
if (!header.size) { | ||
self._parse(512, onheader); | ||
self.emit('entry', header, emptyStream(), oncontinue); | ||
self.emit('entry', header, emptyStream(), onunlock); | ||
return; | ||
} | ||
self._locked = true; | ||
self._stream = new stream.PassThrough(); | ||
@@ -90,3 +96,11 @@ | ||
Extract.prototype.destroy = function() { | ||
if (this._destroyed) return; | ||
this._destroyed = true; | ||
this.emit('close'); | ||
if (this._stream) this._stream.emit('close'); | ||
}; | ||
Extract.prototype._parse = function(size, onparse) { | ||
if (this._destroyed) return; | ||
this._missing = size; | ||
@@ -97,2 +111,3 @@ this._onparse = onparse; | ||
Extract.prototype._continue = function(err) { | ||
if (this._destroyed) return; | ||
var cb = this._cb; | ||
@@ -105,2 +120,4 @@ this._cb = noop; | ||
Extract.prototype._write = function(data, enc, cb) { | ||
if (this._destroyed) return; | ||
var s = this._stream; | ||
@@ -107,0 +124,0 @@ var b = this._buffer; |
@@ -7,8 +7,12 @@ var ZEROS = '0000000000000000000'; | ||
switch (flag) { | ||
case 0: | ||
return 'file'; | ||
case 1: | ||
return 'link'; | ||
case 2: | ||
return 'symlink'; | ||
case 3: | ||
return 'character'; | ||
return 'character-device'; | ||
case 4: | ||
return 'block'; | ||
return 'block-device'; | ||
case 5: | ||
@@ -18,4 +22,7 @@ return 'directory'; | ||
return 'fifo'; | ||
case 7: | ||
return 'contiguous-file' | ||
} | ||
return 'file'; | ||
return null; | ||
}; | ||
@@ -25,7 +32,11 @@ | ||
switch (flag) { | ||
case 'file': | ||
return 0; | ||
case 'link': | ||
return 1; | ||
case 'character': | ||
case 'symlink': | ||
return 2; | ||
case 'character-device': | ||
return 3; | ||
case 'block': | ||
case 'block-device': | ||
return 4; | ||
@@ -36,2 +47,4 @@ case 'directory': | ||
return 6; | ||
case 'contiguous-file': | ||
return 7; | ||
} | ||
@@ -62,3 +75,3 @@ | ||
var oct = function(val, n) { | ||
var encodeOct = function(val, n) { | ||
val = val.toString(8); | ||
@@ -90,7 +103,7 @@ return ZEROS.slice(0, n-val.length)+val+' '; | ||
buf.write(name); | ||
buf.write(oct(opts.mode, 6), 100); | ||
buf.write(oct(opts.uid, 6), 108); | ||
buf.write(oct(opts.gid, 6), 116); | ||
buf.write(oct(opts.size, 11), 124); | ||
buf.write(oct((opts.mtime.getTime() / 1000) | 0, 11), 136); | ||
buf.write(encodeOct(opts.mode & 07777, 6), 100); | ||
buf.write(encodeOct(opts.uid, 6), 108); | ||
buf.write(encodeOct(opts.gid, 6), 116); | ||
buf.write(encodeOct(opts.size, 11), 124); | ||
buf.write(encodeOct((opts.mtime.getTime() / 1000) | 0, 11), 136); | ||
@@ -104,8 +117,8 @@ buf[156] = ZERO_OFFSET + toTypeflag(opts.type); | ||
if (opts.gname) buf.write(opts.gname, 297); | ||
buf.write(oct(0, 6), 329); | ||
buf.write(oct(0, 6), 337); | ||
buf.write(encodeOct(opts.devmajor || 0, 6), 329); | ||
buf.write(encodeOct(opts.devminor || 0, 6), 337); | ||
if (prefix) buf.write(prefix, 345); | ||
buf.write(oct(cksum(buf), 6), 148); | ||
buf.write(encodeOct(cksum(buf), 6), 148); | ||
@@ -116,2 +129,7 @@ return buf; | ||
exports.decode = function(buf) { | ||
var typeflag = buf[156] === 0 ? 0 : buf[156] - ZERO_OFFSET; | ||
var type = toType(typeflag); | ||
if (!type) return null; | ||
var name = decodeStr(buf, 0); | ||
@@ -123,6 +141,7 @@ var mode = decodeOct(buf, 100); | ||
var mtime = decodeOct(buf, 136); | ||
var typeflag = buf[156] - ZERO_OFFSET; | ||
var linkname = buf[157] === 0 ? null : decodeStr(buf, 157); | ||
var uname = decodeStr(buf, 265); | ||
var gname = decodeStr(buf, 297); | ||
var devmajor = decodeOct(buf, 329); | ||
var devminor = decodeOct(buf, 337); | ||
@@ -143,4 +162,6 @@ if (buf[345]) name = decodeStr(buf, 345)+'/'+name; | ||
uname: uname, | ||
gname: gname | ||
gname: gname, | ||
devmajor: devmajor, | ||
devminor: devminor | ||
}; | ||
}; |
31
pack.js
@@ -18,2 +18,3 @@ var stream = require('stream'); | ||
stream.Writable.call(this); | ||
this.written = 0; | ||
this._to = to; | ||
@@ -26,2 +27,3 @@ this._destroyed = false; | ||
Sink.prototype._write = function(data, enc, cb) { | ||
this.written += data.length; | ||
if (this._to.push(data)) return cb(); | ||
@@ -43,3 +45,3 @@ this._to._drain = cb; | ||
this._finalized = false; | ||
this._shouldFinalize = false; | ||
this._finalizing = false; | ||
this._destroyed = false; | ||
@@ -52,2 +54,5 @@ this._stream = null; | ||
Pack.prototype.entry = function(header, buffer, callback) { | ||
if (this._stream) throw new Error('already piping an entry'); | ||
if (this._finalized || this._destroyed) return; | ||
if (typeof buffer === 'function') { | ||
@@ -59,3 +64,2 @@ callback = buffer; | ||
if (!callback) callback = noop; | ||
if (this._stream) throw new Error('already piping an entry'); | ||
@@ -80,2 +84,7 @@ var self = this; | ||
} | ||
if (header.type !== 'file' && header.type !== 'contigious-file') { | ||
this.push(headers.encode(header)); | ||
process.nextTick(callback); | ||
return; | ||
} | ||
@@ -89,6 +98,16 @@ this.push(headers.encode(header)); | ||
self._stream = null; | ||
if (err) { // stream was closed | ||
self.destroy(); | ||
return callback(err); | ||
} | ||
if (sink.written !== header.size) { // corrupting tar | ||
self.destroy(); | ||
return callback(new Error('size mismatch')); | ||
} | ||
overflow(self, header.size); | ||
if (self._shouldFinalize) self.finalize(); | ||
if (err) self.destroy(); | ||
callback(err); | ||
if (self._finalizing) self.finalize(); | ||
callback(); | ||
}); | ||
@@ -101,3 +120,3 @@ | ||
if (this._stream) { | ||
this._shouldFinalize = true; | ||
this._finalizing = true; | ||
return; | ||
@@ -104,0 +123,0 @@ } |
{ | ||
"name": "tar-stream", | ||
"version": "0.1.2", | ||
"description": "tar-stream is a streaming tar parser and generator and nothing else. It is streams2 and operates purely using streams which means easily you can extract/parse tarballs without ever hitting the file system.", | ||
"version": "0.2.0", | ||
"description": "tar-stream is a streaming tar parser and generator and nothing else. It is streams2 and operates purely using streams which means you can easily extract/parse tarballs without ever hitting the file system.", | ||
"repository": "git://github.com:mafintosh/tar-stream.git", | ||
@@ -11,18 +11,25 @@ "author": "Mathias Buus <mathiasbuus@gmail.com>", | ||
}, | ||
"devDependencies": { | ||
"tap": "~0.4.6", | ||
"concat-stream": "~1.2.1" | ||
}, | ||
"scripts": { | ||
"test": "tap test/*.js" | ||
}, | ||
"keywords": [ | ||
"tar", | ||
"tarball", | ||
"parse", | ||
"parser", | ||
"generate", | ||
"generator", | ||
"stream", | ||
"stream2", | ||
"streams", | ||
"streams2", | ||
"streaming", | ||
"pack", | ||
"extract", | ||
"modify" | ||
"tar", | ||
"tarball", | ||
"parse", | ||
"parser", | ||
"generate", | ||
"generator", | ||
"stream", | ||
"stream2", | ||
"streams", | ||
"streams2", | ||
"streaming", | ||
"pack", | ||
"extract", | ||
"modify" | ||
] | ||
} |
@@ -7,2 +7,4 @@ # tar-stream | ||
[![build status](https://secure.travis-ci.org/mafintosh/tar-stream.png)](http://travis-ci.org/mafintosh/tar-stream) | ||
# Usage | ||
@@ -26,7 +28,6 @@ | ||
// the stream was added | ||
// no more entries | ||
pack.finalize(); | ||
})); | ||
// no more entries | ||
pack.finalize(); | ||
// pipe the pack stream somewhere | ||
@@ -71,9 +72,13 @@ pack.pipe(process.stdout); | ||
mode: 0644, // entry mode. defaults to to 0755 for dirs and 0644 otherwise | ||
mtime: new Date(), // last modified date for entry | ||
type: 'file', // type of entry. can be file|directory|link|block|character|fifo | ||
linkname: 'path', // | ||
mtime: new Date(), // last modified date for entry. defaults to now. | ||
type: 'file', // type of entry. defaults to file. can be: | ||
// file | link | symlink | directory | block-device | ||
// character-device | fifo | contigious-file | ||
linkname: 'path', // linked file name | ||
uid: 0, // uid of entry owner. defaults to 0 | ||
gid: 0, // gid of entry owner. defaults to 0 | ||
uname: 'maf', // uname of entry owner. defaults to null | ||
gname: 'wheel', // gname of entry owner. defaults to null | ||
gname: 'staff', // gname of entry owner. defaults to null | ||
devmajor: 0, // device major version. defaults to 0 | ||
devminor: 0 // device minor version. defaults to 0 | ||
} | ||
@@ -80,0 +85,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
45520
17
798
115
2
3
1