mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-29 21:37:58 +00:00
src/telegram: Populate Stream#path from TelegramBot#getFileStream()
This commit is contained in:
parent
b91409a2b6
commit
b968e893d3
@ -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 |
|
||||
| --- | --- | --- |
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user