2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-30 13:58:27 +00:00

src/telegram: Populate Stream#path from TelegramBot#getFileStream()

This commit is contained in:
GochoMugo 2017-12-08 19:18:55 +03:00
parent b91409a2b6
commit b968e893d3
No known key found for this signature in database
GPG Key ID: 7B6A01CB57AA39E4
3 changed files with 6 additions and 2 deletions

View File

@ -846,12 +846,13 @@ which returns just path to file on remote server (you will have to manually buil
### telegramBot.getFileStream(fileId, [options]) ⇒ <code>stream.Readable</code>
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 <code>[TelegramBot](#TelegramBot)</code>
**Returns**: <code>stream.Readable</code> - stream
**Returns**: <code>stream.Readable</code> - fileStream
| Param | Type | Description |
| --- | --- | --- |

View File

@ -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);

View File

@ -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();