fake.returns({ restart: fake.resolves(true), exec: ({ Cmd }) => { const mockedStream = new stream.Readable(); return fake.resolves({ start: sinon.stub().yields(Cmd[0] === 'fail' ? 'error' : null, mockedStream), })(); }, })
function isReadableStream(obj) { return ( obj instanceof stream.Stream && (getType(obj._read) === "Function" || getType(obj._read) === "AsyncFunction") && getType(obj._readableState) === "Object" ); }
describe('#getFileStream', function getFileStreamSuite() { this.timeout(timeout); before(function before() { // utils.handleRatelimit(bot, 'getFileStream', this); }); it('should get a file stream', function test(done) { const fileStream = bot.getFileStream(FILE_ID); assert.ok(fileStream instanceof stream.Readable); assert.equal(fileStream.path, FILE_ID); fileStream.on('info', (info) => { assert.ok(info); assert.ok(utils.isTelegramFileURI(info.uri), `${info.uri} is not a file URI`); fileStream.pipe(concat(function readFile(buffer) { buffer.equals(fs.readFileSync(FILE_PATH)); // sync :( return done(); })); }); }); });
let tarStream = new stream.PassThrough();
/** * 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; }
transit.opts.maxChunkSize = 100; let randomData = crypto.randomBytes(1024); let stream = new Stream.Readable({ read() {} });
let tarStream = new stream.PassThrough();
if (typeof options !== 'object' || options instanceof stream.Stream) { deprecate('The method signature setWebHook(url, cert) has been deprecated since v0.25.0'); cert = options;
let contentType = fileOptions.contentType; if (data instanceof stream.Stream) { if (!filename && data.path) {
it("should send stream chunks", () => { transit.publish.mockClear(); let stream = new Stream.Readable({ read() {} });
it("should send stream error", () => { transit.publish.mockClear(); let stream = new Stream.Readable({ read() {} });
transit.opts.maxChunkSize = 100; let randomData = crypto.randomBytes(256); // length > maxChunkSize => will be splitted to several chunks let stream = new Stream.PassThrough();
transit.opts.maxChunkSize = 100; let randomData = crypto.randomBytes(1024); let stream = new Stream.Readable({ read() {} });
it("should send stream chunks", () => { transit.publish.mockClear(); let stream = new Stream.Readable({ read() {} });
fake.returns({ restart: fake.resolves(true), exec: ({ Cmd }) => { const mockedStream = new stream.Readable(); return fake.resolves({ start: sinon.stub().yields(Cmd[0] === 'fail' ? 'error' : null, mockedStream), })(); }, })