mirror of
https://github.com/a-sync/game-server-watcher.git
synced 2026-08-02 02:19:08 -04:00
upd. deps (5.7 MB)
This commit is contained in:
29
node_modules/get-stream/buffer-stream.js
generated
vendored
29
node_modules/get-stream/buffer-stream.js
generated
vendored
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user