/** * Return a readable stream for file. * * `fileStream.path` is the specified file ID i.e. `fileId`. * `fileStream` emits event `info` passing a single argument i.e. * `info` with the interface `{ uri }` where `uri` is the URI of the * file on Telegram servers. * * This method is a sugar extension of the [getFileLink](#TelegramBot+getFileLink) method, * which returns the full URI to the file on remote server. * * @param {String} fileId File identifier to get info about * @param {Object} [options] Additional Telegram query options * @return {stream.Readable} fileStream */ getFileStream(fileId, form = {}) { const fileStream = new stream.PassThrough(); fileStream.path = fileId; this.getFileLink(fileId, form) .then((fileURI) => { fileStream.emit('info', { uri: fileURI, }); pump(streamedRequest(Object.assign({ uri: fileURI }, this.options.request)), fileStream); }) .catch((error) => { fileStream.emit('error', error); }); return fileStream; }
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); });
getLogByteStream (options) { const log = new this.client.Log(this.kubeconfig) const qs = options.qs || options.parameters || {} const containerName = qs.container const stream = new PassThrough() // // node-client pipes to the log stream iff the apiserver returns 200. Assume // that if the stream is readable, then node-client has attached the pipe // and the call was successful. // // Otherwise, node-client calls the callback with an err. // // node-client also calls the callback when the connection terminates. We // ignore that. // return new Promise((resolve, reject) => { stream.once('readable', () => { resolve(stream) }) log.log(options.pathnameParameters.namespace, options.pathnameParameters.name, containerName, stream, err => { if (err) return reject(err) }, qs) }) }
writeStream.on('end', function() { var b = Buffer.concat(this.data); payload.data = mime + b.toString('base64'); payload.optimized_size = payload.data.length; logger.info(app_id, 'optimized_to', payload.data.length); socket.emit('fruum:optimize', payload); });
startStream(offset) { this.offset = this.hashes.findIndex(h => offset <= h.offset + h.size); Log.debug('starting to download from offset: ', offset, `${this.offset}/${this.hashes.length - 1}`); this.skipBytes = offset - this.hashes[this.offset].offset; this.output = new PassThrough(); this.output.on('close', this.end.bind(this)); this.downloadNext(); return this.output; }
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; }
combine( fs.createReadStream(process.argv[3]) .pipe(compressAndEncryptStream(process.argv[2])) .pipe(fs.createWriteStream(process.argv[3] + ".gz.enc")) ).on('error', err => { //this error may come from any stream in the pipeline console.log(err); }) ;
function createReadStream(filePath, options) { const Stream = require("stream"); const PassThroughStream = Stream.PassThrough; const outStream = new PassThroughStream(); getFileStream(filePath, options) .then(stream => { stream.pipe(outStream); }) .catch(err => { outStream.emit("error", err); }); return outStream; }
var interceptorFactory2 = function() { var interceptor = new stream.PassThrough() interceptor.on('end', function() { intercepted2 = true }) return interceptor }
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); });