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:
@@ -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>
|
### telegramBot.getFileStream(fileId, [options]) ⇒ <code>stream.Readable</code>
|
||||||
Return a readable stream for file.
|
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,
|
This method is a sugar extension of the [getFileLink](#TelegramBot+getFileLink) method,
|
||||||
which returns the full URI to the file on remote server.
|
which returns the full URI to the file on remote server.
|
||||||
|
|
||||||
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
|
||||||
**Returns**: <code>stream.Readable</code> - stream
|
**Returns**: <code>stream.Readable</code> - fileStream
|
||||||
|
|
||||||
| Param | Type | Description |
|
| Param | Type | Description |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
|
@@ -1324,16 +1324,18 @@ class TelegramBot extends EventEmitter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a readable stream for file.
|
* 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,
|
* This method is a sugar extension of the [getFileLink](#TelegramBot+getFileLink) method,
|
||||||
* which returns the full URI to the file on remote server.
|
* which returns the full URI to the file on remote server.
|
||||||
*
|
*
|
||||||
* @param {String} fileId File identifier to get info about
|
* @param {String} fileId File identifier to get info about
|
||||||
* @param {Object} [options] Additional Telegram query options
|
* @param {Object} [options] Additional Telegram query options
|
||||||
* @return {stream.Readable} stream
|
* @return {stream.Readable} fileStream
|
||||||
*/
|
*/
|
||||||
getFileStream(fileId, form = {}) {
|
getFileStream(fileId, form = {}) {
|
||||||
const fileStream = new stream.PassThrough();
|
const fileStream = new stream.PassThrough();
|
||||||
|
fileStream.path = fileId;
|
||||||
this.getFileLink(fileId, form)
|
this.getFileLink(fileId, form)
|
||||||
.then((fileURI) => {
|
.then((fileURI) => {
|
||||||
pump(streamedRequest({ uri: fileURI }), fileStream);
|
pump(streamedRequest({ uri: fileURI }), fileStream);
|
||||||
|
@@ -1173,6 +1173,7 @@ describe('TelegramBot', function telegramSuite() {
|
|||||||
it('should get a file stream', function test(done) {
|
it('should get a file stream', function test(done) {
|
||||||
const fileStream = bot.getFileStream(FILE_ID);
|
const fileStream = bot.getFileStream(FILE_ID);
|
||||||
assert.ok(fileStream instanceof stream.Readable);
|
assert.ok(fileStream instanceof stream.Readable);
|
||||||
|
assert.equal(fileStream.path, FILE_ID);
|
||||||
fileStream.pipe(concat(function readFile(buffer) {
|
fileStream.pipe(concat(function readFile(buffer) {
|
||||||
buffer.equals(fs.readFileSync(FILE_PATH)); // sync :(
|
buffer.equals(fs.readFileSync(FILE_PATH)); // sync :(
|
||||||
return done();
|
return done();
|
||||||
|
Reference in New Issue
Block a user