Skip to content

Commit

Permalink
Added gzip helper option.
Browse files Browse the repository at this point in the history
  • Loading branch information
jstuckey committed Mar 21, 2014
1 parent 8185ae0 commit 40ae8f5
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/modules/tar/index.js
Expand Up @@ -7,14 +7,16 @@
*/
var inherits = require('util').inherits;
var Transform = require('stream').Transform || require('readable-stream').Transform;
var zlib = require('zlib');

var headers = require('./headers');
var util = require('../../util');

var Tar = module.exports = function(options) {
options = this.options = util.defaults(options, {
recordSize: 512,
recordsPerBlock: 20
recordsPerBlock: 20,
gzip: false
});

Transform.call(this, options);
Expand All @@ -24,6 +26,11 @@ var Tar = module.exports = function(options) {

this.recordSize = options.recordSize;
this.blockSize = options.recordsPerBlock * options.recordSize;
this.gzip = options.gzip;

if (this.gzip) {
this.gzipper = zlib.createGzip();
}
};

inherits(Tar, Transform);
Expand Down Expand Up @@ -95,4 +102,14 @@ Tar.prototype.write = function(chunk, cb) {
}

return Transform.prototype.write.call(this, chunk, cb);
};

Tar.prototype.pipe = function(destination, options) {
if (this.gzip && this.gzipper) {
// Pipe to gzip stream before piping to destination
return Transform.prototype.pipe.call(this, this.gzipper, options).pipe(destination);
} else {
// Pipe to the destination like normal
return Transform.prototype.pipe.call(this, destination, options)
}
};

0 comments on commit 40ae8f5

Please sign in to comment.