make use of readable-stream.

This commit is contained in:
Chris Talkington 2014-01-05 16:23:17 -06:00
parent a1eb4ba9f6
commit a4b45be319
2 changed files with 14 additions and 8 deletions

View file

@ -3,6 +3,9 @@ var util = require('util');
var bl = require('bl');
var headers = require('./headers');
var Writable = stream.Writable;
var PassThrough = stream.PassThrough || require('readable-stream').PassThrough;
var noop = function() {};
var overflow = function(size) {
@ -11,7 +14,7 @@ var overflow = function(size) {
};
var emptyStream = function() {
var s = new stream.PassThrough();
var s = new PassThrough();
s.end();
return s;
};
@ -24,7 +27,7 @@ var mixinPax = function(header, pax) {
var Extract = function(opts) {
if (!(this instanceof Extract)) return new Extract(opts);
stream.Writable.call(this, opts);
Writable.call(this, opts);
this._buffer = bl();
this._missing = 0;
@ -99,7 +102,7 @@ var Extract = function(opts) {
return;
}
self._stream = new stream.PassThrough();
self._stream = new PassThrough();
self.emit('entry', header, self._stream, onunlock);
self._parse(header.size, onstreamend);
@ -109,7 +112,7 @@ var Extract = function(opts) {
this._parse(512, onheader);
};
util.inherits(Extract, stream.Writable);
util.inherits(Extract, Writable);
Extract.prototype.destroy = function(err) {
if (this._destroyed) return;

11
pack.js
View file

@ -3,6 +3,9 @@ var util = require('util');
var eos = require('end-of-stream');
var headers = require('./headers');
var Readable = stream.Readable;
var Writable = stream.Writable;
var END_OF_TAR = new Buffer(1024);
END_OF_TAR.fill(0);
@ -14,13 +17,13 @@ var overflow = function(self, size) {
};
var Sink = function(to) {
stream.Writable.call(this);
Writable.call(this);
this.written = 0;
this._to = to;
this._destroyed = false;
};
util.inherits(Sink, stream.Writable);
util.inherits(Sink, Writable);
Sink.prototype._write = function(data, enc, cb) {
this.written += data.length;
@ -36,7 +39,7 @@ Sink.prototype.destroy = function() {
var Pack = function(opts) {
if (!(this instanceof Pack)) return new Pack(opts);
stream.Readable.call(this, opts);
Readable.call(this, opts);
this._drain = noop;
this._finalized = false;
@ -45,7 +48,7 @@ var Pack = function(opts) {
this._stream = null;
};
util.inherits(Pack, stream.Readable);
util.inherits(Pack, Readable);
Pack.prototype.entry = function(header, buffer, callback) {
if (this._stream) throw new Error('already piping an entry');