| ; | |
| const {PassThrough: PassThroughStream} = require('stream'); | |
| module.exports = options => { | |
| options = {...options}; | |
| const {array} = options; | |
| let {encoding} = options; | |
| const isBuffer = encoding === 'buffer'; | |
| let objectMode = false; | |
| if (array) { | |
| objectMode = !(encoding || isBuffer); | |
| } else { | |
| encoding = encoding || 'utf8'; | |
| } | |
| if (isBuffer) { | |
| encoding = null; | |
| } | |
| const stream = new PassThroughStream({objectMode}); | |
| if (encoding) { | |
| stream.setEncoding(encoding); | |
| } | |
| let length = 0; | |
| const chunks = []; | |
| stream.on('data', chunk => { | |
| chunks.push(chunk); | |
| if (objectMode) { | |
| length = chunks.length; | |
| } else { | |
| length += chunk.length; | |
| } | |
| }); | |
| stream.getBufferedValue = () => { | |
| if (array) { | |
| return chunks; | |
| } | |
| return isBuffer ? Buffer.concat(chunks, length) : chunks.join(''); | |
| }; | |
| stream.getBufferedLength = () => length; | |
| return stream; | |
| }; | |
Xet Storage Details
- Size:
- 894 Bytes
- Xet hash:
- c36d133460935c6383bbe513522c35b12cc923b290c0b656625f2a59900cbf12
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.