diff --git a/headers.js b/headers.js index 0548213..cf978e1 100644 --- a/headers.js +++ b/headers.js @@ -1,3 +1,6 @@ +var toBuffer = require('to-buffer') +var alloc = require('buffer-alloc') + var ZEROS = '0000000000000000000' var SEVENS = '7777777777777777777' var ZERO_OFFSET = '0'.charCodeAt(0) @@ -71,12 +74,6 @@ var toTypeflag = function (flag) { return 0 } -var alloc = function (size) { - var buf = new Buffer(size) - buf.fill(0) - return buf -} - var indexOf = function (block, num, offset, end) { for (; offset < end; offset++) { if (block[offset] === num) return offset @@ -175,7 +172,7 @@ exports.encodePax = function (opts) { // TODO: encode more stuff in pax result += addLength(' ' + key + '=' + pax[key] + '\n') } } - return new Buffer(result) + return toBuffer(result) } exports.decodePax = function (buf) { diff --git a/pack.js b/pack.js index 025f007..0bb57f6 100644 --- a/pack.js +++ b/pack.js @@ -1,6 +1,8 @@ var constants = require('constants') var eos = require('end-of-stream') var util = require('util') +var alloc = require('buffer-alloc') +var toBuffer = require('to-buffer') var Readable = require('readable-stream').Readable var Writable = require('readable-stream').Writable @@ -11,8 +13,7 @@ var headers = require('./headers') var DMODE = parseInt('755', 8) var FMODE = parseInt('644', 8) -var END_OF_TAR = new Buffer(1024) -END_OF_TAR.fill(0) +var END_OF_TAR = alloc(1024) var noop = function () {} @@ -124,7 +125,7 @@ Pack.prototype.entry = function (header, buffer, callback) { if (!header.gid) header.gid = 0 if (!header.mtime) header.mtime = new Date() - if (typeof buffer === 'string') buffer = new Buffer(buffer) + if (typeof buffer === 'string') buffer = toBuffer(buffer) if (Buffer.isBuffer(buffer)) { header.size = buffer.length this._encode(header) diff --git a/package.json b/package.json index 2a25292..717b285 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,10 @@ }, "dependencies": { "bl": "^1.0.0", + "buffer-alloc": "^1.1.0", "end-of-stream": "^1.0.0", "readable-stream": "^2.0.0", + "to-buffer": "^1.1.0", "xtend": "^4.0.0" }, "devDependencies": {