tarStream.pipe(extract);
tarStream.pipe(extract);
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))); });
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); });
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); } } });
cases.forEach(function (testCase) { test(testCase.name, function (t) { const source = new stream.PassThrough() const upcase = new stream.Transform({ transform (chunk, enc, cb) { cb(null, chunk.toString().toUpperCase()) } }) const target = new stream.PassThrough() if (testCase.source) agent._instrumentation.bindEmitter(source) if (testCase.target) agent._instrumentation.bindEmitter(target) mimicResponse(source, target) target.on('data', function (chunk) { t.ok(this === target, 'target -> onData should be bound to target stream') t.strictEqual(chunk.toString(), 'HELLO WORLD') t.end() }) source.pipe(upcase).pipe(target) source.end('hello world') }) })
/* Generate thumbnail */ router.get('/generatethumb', function(req, res) { exec("gm -help", function (err) { if (err) { res.status(500).send({ error: 'GraphicsMagick is not installed' }) } else { res.setHeader("content-type", "image/png"); gm(path.join(serverRoot, req.query.f)) .resize(req.query.width || '200', req.query.height || '200', '^') .gravity('Center') .crop(req.query.width || '200', req.query.height || '200') .stream('png') .pipe(res); } }); });
it('streaming works, string, buffered client, stream sent back', (done) => { serviceStr.on('stream', (req, res, meta, handler) => { assert.strictEqual(meta.isStream, false) req.on('data', (d) => { const [rid, key, args] = JSON.parse(d.toString()) assert.strictEqual(args, 'hello') assert.ok(typeof rid === 'string') assert.strictEqual(key, 'rpc_stream') const writable = new PassThrough() const payload = JSON.stringify([rid, null, 'world2']) writable.pipe(res) writable.write(payload) writable.end() }) }) const opts = { timeout: 100000 } peer.request('rpc_stream', 'hello', opts, (err, result) => { if (err) throw err assert.strictEqual(result, 'world2') stop() done() }) }).timeout(7000)
test('basic test', function (t) { t.plan(2) var elem = createElem('video') var readable = new stream.PassThrough() var wrapper = new MediaElementWrapper(elem) var writable = wrapper.createWriteStream(CODEC_TYPE) readable.on('error', function (err) { t.fail(err) }) writable.on('error', function (err) { t.fail(err) }) elem.addEventListener('error', function (err) { t.fail(err) }) elem.addEventListener('playing', function () { t.pass('got the "playing" event') }) elem.addEventListener('progress', onProgress) function onProgress () { t.pass('got a "progress" event') elem.removeEventListener('progress', onProgress) } readable.pipe(writable) readable.write(FILE) })
it('should encode heartbeat', async function() { const sentReqs = new Map(); const socket = new PassThrough(); const encoder = protocol.encoder({ sentReqs, address }); const decoder = protocol.decoder({ sentReqs }); encoder.pipe(socket).pipe(decoder); setImmediate(() => { encoder.writeHeartbeat(1, { clientUrl: 'xxx' }); }); const hb = await awaitEvent(decoder, 'heartbeat'); assert(hb.packetId === 1); assert(hb.packetType === 'heartbeat'); assert(hb.options && hb.options.protocolType === protocolType); assert(hb.options.codecType === codecType); if (protocolType === 'bolt') { assert(hb.options.timeout === 3000); } setImmediate(() => { encoder.writeHeartbeatAck(hb); }); const hbAck = await awaitEvent(decoder, 'heartbeat_ack'); assert(hbAck.packetId === 1); assert(hbAck.packetType === 'heartbeat_ack'); assert(hbAck.options && hbAck.options.protocolType === protocolType); assert(hbAck.options.codecType === codecType); });
writable.write('["UUID", "rpc_buf", { "hello": "world" }]') writable.end() writable.pipe(req) }).timeout(7000)
readable.pipe(writable) readable.write(FILE) })
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); });
it('pipe, 10 Mb body with 1 Kb compression chunks', (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); }, { chunkSize: 1024 } ); request(step) .get('/') .set('accept-encoding', 'gzip') .expect(header('content-encoding', 'gzip')) .expect(header('transfer-encoding', 'chunked')) .expect(size(body.length)) .expect(200, done); });