tarStream.end(result); tarStream.pipe(extract);
}); tarStream.end(result); tarStream.pipe(extract);
let randomData = crypto.randomBytes(256); // length > maxChunkSize => will be splitted to several chunks let stream = new Stream.PassThrough(); stream.end(randomData); // end stream before giving stream to transit => transit will receive "data" and "end" event immediately one after the other ctx.params = stream;
it("should accept Readable streams with deferred size", async function () { var input = new stream.PassThrough(); var options = { httpStack: new TestHttpStack(), endpoint: "/uploads", chunkSize: 7, uploadLengthDeferred: true }; input.end("hello WORLD"); await expectHelloWorldUpload(input, options); });
ray .bridge('/pipe-sm') .through(compress()) .get((req, res) => { res.setHeader('Content-Type', 'application/json'); const bufferStream = new PassThrough(); bufferStream.pipe(res); bufferStream.end(Buffer.from(JSON.stringify(payload))); });
const importFile = function (buffer, container, filename) { const bufferStream = new stream.PassThrough() bufferStream.end(buffer) return storage.store(container, filename, bufferStream) }
async getUnpublishedEventStream () { const filteredEvents = this.getStoredEvents(). filter(event => event.metadata.published === false); const passThrough = new PassThrough({ objectMode: true }); filteredEvents.forEach(event => { passThrough.write(Event.deserialize(event)); }); passThrough.end(); return passThrough; }
end(data, encoding) { this.decompressor.end(data, encoding) }
originController.createOrigin(`${opts.prefix || '/identicon'}/:token`, async ({ token, size, width }) => { debug('Identicon origin'); // We can use any size/width param from the recipe to make sure the size will match const reqOpts = Object.assign({}, opts); if (size) reqOpts.size = size; else if (width) reqOpts.size = width; const img = new Identicon(token, reqOpts); const bufferStream = new stream.PassThrough(); bufferStream.end(await img.render()); return bufferStream; })
Polly.synthesizeSpeech(params, (err, data) => { if (err) { console.log(err.code); } else if (data) { if (data.AudioStream instanceof Buffer) { // Initiate the source var bufferStream = new Stream.PassThrough(); // convert AudioStream into a readable stream bufferStream.end(data.AudioStream); // Pipe into Player bufferStream.pipe(Player); } } });
async getReplay (options) { options = options || {}; const fromPosition = options.fromPosition || 1; const toPosition = options.toPosition || 2 ** 31 - 1; if (fromPosition > toPosition) { throw new Error('From position is greater than to position.'); } const passThrough = new PassThrough({ objectMode: true }); const filteredEvents = this.getStoredEvents(). filter(event => event.metadata.position >= fromPosition && event.metadata.position <= toPosition); filteredEvents.forEach(event => { passThrough.write(Event.deserialize(event)); }); passThrough.end(); return passThrough; }
async _perform(data){ // text input if (data.type === 'text'){ const bufferStream = new stream.PassThrough(); bufferStream.end(Buffer.from('test')); // setting a custom content type this.setMeta('handler.web.writeOptions', { headers: { contentType: 'text/plain', }, }); return bufferStream; } // binary return readFile(data.file); }
it('pipe, 1 Mb body', (done) => { const body = Buffer.alloc(1000000, '.'); const step = wrap(compress, (req, res) => { res.setHeader('content-type', 'text/plain'); const bufferStream = new PassThrough(); bufferStream.pipe(res); bufferStream.end(body); }); request(step) .get('/') .set('accept-encoding', 'gzip') .expect(header('content-encoding', 'gzip')) .expect(header('transfer-encoding', 'chunked')) .expect(size(body.length)) .expect(200, done); });
it("should accept Readable streams", async function () { var input = new stream.PassThrough(); var options = { httpStack: new TestHttpStack(), endpoint: "/uploads", chunkSize: 7, uploadSize: 11 }; input.end("hello WORLD"); await expectHelloWorldUpload(input, options); });
it('pipe, 10 Mb body', (done) => { const body = Buffer.alloc(1e7, '.'); const step = wrap(compress, (req, res) => { res.setHeader('content-type', 'text/plain'); const bufferStream = new PassThrough(); bufferStream.pipe(res); bufferStream.end(body); }); request(step) .get('/') .set('accept-encoding', 'gzip') .expect(header('content-encoding', 'gzip')) .expect(header('transfer-encoding', 'chunked')) .expect(size(body.length)) .expect(200, done); });