From a4b45be3190b68a3de5bd6aef896184e682104a5 Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Sun, 5 Jan 2014 16:23:17 -0600 Subject: [PATCH] make use of readable-stream. --- extract.js | 11 +++++++---- pack.js | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/extract.js b/extract.js index f6e7b51..3d682d1 100644 --- a/extract.js +++ b/extract.js @@ -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; diff --git a/pack.js b/pack.js index a4ad380..9b94edd 100644 --- a/pack.js +++ b/pack.js @@ -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');