upd. deps (5.7 MB)

This commit is contained in:
Smith
2022-07-21 10:36:57 +02:00
parent b2ace6f5e3
commit e7a397abc0
106 changed files with 2234 additions and 2424 deletions

View File

@@ -1,51 +1,52 @@
'use strict';
const {PassThrough} = require('stream');
const {PassThrough: PassThroughStream} = require('stream');
module.exports = options => {
options = Object.assign({}, options);
options = {...options};
const {array} = options;
let {encoding} = options;
const buffer = encoding === 'buffer';
const isBuffer = encoding === 'buffer';
let objectMode = false;
if (array) {
objectMode = !(encoding || buffer);
objectMode = !(encoding || isBuffer);
} else {
encoding = encoding || 'utf8';
}
if (buffer) {
if (isBuffer) {
encoding = null;
}
let len = 0;
const ret = [];
const stream = new PassThrough({objectMode});
const stream = new PassThroughStream({objectMode});
if (encoding) {
stream.setEncoding(encoding);
}
let length = 0;
const chunks = [];
stream.on('data', chunk => {
ret.push(chunk);
chunks.push(chunk);
if (objectMode) {
len = ret.length;
length = chunks.length;
} else {
len += chunk.length;
length += chunk.length;
}
});
stream.getBufferedValue = () => {
if (array) {
return ret;
return chunks;
}
return buffer ? Buffer.concat(ret, len) : ret.join('');
return isBuffer ? Buffer.concat(chunks, length) : chunks.join('');
};
stream.getBufferedLength = () => len;
stream.getBufferedLength = () => length;
return stream;
};