diff --git a/doc/api.md b/doc/api.md index 641f11a..a4e6956 100644 --- a/doc/api.md +++ b/doc/api.md @@ -846,12 +846,13 @@ which returns just path to file on remote server (you will have to manually buil ### telegramBot.getFileStream(fileId, [options]) ⇒ stream.Readable Return a readable stream for file. +`fileStream.path` is the specified file ID i.e. `fileId`. This method is a sugar extension of the [getFileLink](#TelegramBot+getFileLink) method, which returns the full URI to the file on remote server. **Kind**: instance method of [TelegramBot](#TelegramBot) -**Returns**: stream.Readable - stream +**Returns**: stream.Readable - fileStream | Param | Type | Description | | --- | --- | --- | diff --git a/src/telegram.js b/src/telegram.js index 73c293b..5bd5b46 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -1324,16 +1324,18 @@ class TelegramBot extends EventEmitter { /** * Return a readable stream for file. + * `fileStream.path` is the specified file ID i.e. `fileId`. * * 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} stream + * @return {stream.Readable} fileStream */ getFileStream(fileId, form = {}) { const fileStream = new stream.PassThrough(); + fileStream.path = fileId; this.getFileLink(fileId, form) .then((fileURI) => { pump(streamedRequest({ uri: fileURI }), fileStream); diff --git a/test/telegram.js b/test/telegram.js index a0de9ff..cfbf303 100644 --- a/test/telegram.js +++ b/test/telegram.js @@ -1173,6 +1173,7 @@ describe('TelegramBot', function telegramSuite() { 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.pipe(concat(function readFile(buffer) { buffer.equals(fs.readFileSync(FILE_PATH)); // sync :( return done();