GramIO API Reference / @gramio/files/dist / TelegramFileDownload
Class: TelegramFileDownload
Defined in: files/index.d.ts:167
Lazy, Response-like handle for downloading a Telegram file.
It is a PromiseLike<ArrayBuffer> — so await download still yields the bytes, exactly like before — plus convenience readers, mirroring the web Response:
const dl = ctx.download(); // nothing fetched yet
await dl.bytes(); // Uint8Array
await dl.text(); // string (utf-8)
await dl.json(); // parsed JSON
await dl.blob(); // Blob
await dl.stream(); // ReadableStream (pipe huge files)
await dl.toFile("./photo.jpg"); // save to disk, returns the path
await dl.info(); // getFile metadata (no body read)
const buf = await ctx.download(); // ArrayBuffer (back-compatible)Like Response, the body is single-use: read it once, then call download() again for another pass. info() and toFile() (for a local server file) don't consume the body.
Implements
PromiseLike<ArrayBuffer>
Constructors
Constructor
new TelegramFileDownload(
resolver):TelegramFileDownload
Defined in: files/index.d.ts:169
Parameters
| Parameter | Type |
|---|---|
resolver | FileDownloadResolver |
Returns
TelegramFileDownload
Methods
arrayBuffer()
arrayBuffer():
Promise<ArrayBuffer>
Defined in: files/index.d.ts:175
The whole file as an ArrayBuffer.
Returns
Promise<ArrayBuffer>
blob()
blob():
Promise<Blob>
Defined in: files/index.d.ts:179
The whole file as a Blob.
Returns
Promise<Blob>
bytes()
bytes():
Promise<Uint8Array<ArrayBufferLike>>
Defined in: files/index.d.ts:177
The whole file as a Uint8Array.
Returns
Promise<Uint8Array<ArrayBufferLike>>
info()
info():
Promise<TelegramFile>
Defined in: files/index.d.ts:173
The getFile metadata (file_id, file_path, file_size, …). Does not read the body.
Returns
Promise<TelegramFile>
json()
json<
T>():Promise<T>
Defined in: files/index.d.ts:183
The file parsed as JSON.
Type Parameters
| Type Parameter | Default type |
|---|---|
T | unknown |
Returns
Promise<T>
link()
link():
Promise<string>
Defined in: files/index.d.ts:198
A download URL for the file. Does not read the body.
⚠️ Contains the bot token by default — the standard Telegram URL is …/file/bot<token>/<path>. It is token-less only when files.baseURL is set (a local server serving the working dir over HTTP), where it becomes ${files.baseURL}/<path>. Don't hand the default (token-bearing) link to end users; configure files.baseURL, or proxy downloads yourself.
Throws for a local-server file (--local, absolute path) with no files.baseURL — there's no HTTP URL, only a path on the server's disk.
Returns
Promise<string>
stream()
stream():
Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>
Defined in: files/index.d.ts:185
A web ReadableStream of the file — pipe large files without buffering.
Returns
Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>
text()
text():
Promise<string>
Defined in: files/index.d.ts:181
The file decoded as UTF-8 text.
Returns
Promise<string>
then()
then<
TResult1,TResult2>(onfulfilled?,onrejected?):Promise<TResult1|TResult2>
Defined in: files/index.d.ts:202
PromiseLike: await download resolves the file bytes (back-compatible).
Type Parameters
| Type Parameter | Default type |
|---|---|
TResult1 | ArrayBuffer |
TResult2 | never |
Parameters
| Parameter | Type |
|---|---|
onfulfilled? | (value) => TResult1 | PromiseLike<TResult1> |
onrejected? | (reason) => TResult2 | PromiseLike<TResult2> |
Returns
Promise<TResult1 | TResult2>
Implementation of
PromiseLike.then
toFile()
toFile(
path):Promise<string>
Defined in: files/index.d.ts:200
Save the file to path and return it. Copies on disk when possible (no extra transfer).
Parameters
| Parameter | Type |
|---|---|
path | string |
Returns
Promise<string>