minipass-collect
Advanced tools
Comparing version 1.0.0 to 1.0.1
48
index.js
@@ -10,14 +10,26 @@ const Minipass = require('minipass') | ||
} | ||
write (chunk, enc) { | ||
const c = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, enc) | ||
write (chunk, encoding, cb) { | ||
if (typeof encoding === 'function') | ||
cb = encoding, encoding = 'utf8' | ||
if (!encoding) | ||
encoding = 'utf8' | ||
const c = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding) | ||
this[_data].push(c) | ||
this[_length] += c.length | ||
if (cb) | ||
cb() | ||
return true | ||
} | ||
end (chunk, enc) { | ||
if (chunk || enc) | ||
this.write(chunk, enc) | ||
end (chunk, encoding, cb) { | ||
if (typeof chunk === 'function') | ||
cb = chunk, chunk = null | ||
if (typeof encoding === 'function') | ||
cb = encoding, encoding = 'utf8' | ||
if (chunk) | ||
this.write(chunk, encoding) | ||
const result = Buffer.concat(this[_data], this[_length]) | ||
super.write(result) | ||
return super.end() | ||
return super.end(cb) | ||
} | ||
@@ -36,16 +48,26 @@ } | ||
} | ||
write (chunk, enc) { | ||
const c = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, enc) | ||
write (chunk, encoding, cb) { | ||
if (typeof encoding === 'function') | ||
cb = encoding, encoding = 'utf8' | ||
if (!encoding) | ||
encoding = 'utf8' | ||
const c = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding) | ||
this[_data].push(c) | ||
this[_length] += c.length | ||
return super.write(chunk, enc) | ||
return super.write(chunk, encoding, cb) | ||
} | ||
end (chunk, enc) { | ||
if (chunk || enc) | ||
this.write(chunk, enc) | ||
end (chunk, encoding, cb) { | ||
if (typeof chunk === 'function') | ||
cb = chunk, chunk = null | ||
if (typeof encoding === 'function') | ||
cb = encoding, encoding = 'utf8' | ||
if (chunk) | ||
this.write(chunk, encoding) | ||
const result = Buffer.concat(this[_data], this[_length]) | ||
this.emit('collect', result) | ||
return super.end() | ||
return super.end(cb) | ||
} | ||
} | ||
module.exports.PassThrough = CollectPassThrough |
{ | ||
"name": "minipass-collect", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A Minipass stream that collects all the data into a single chunk", | ||
@@ -5,0 +5,0 @@ "author": "Isaac Z. Schlueter <i@izs.me> (https://izs.me)", |
4258
66