feat: support big file downloads (read from WA cache + streaming) (#201697)

* feat: support big file downloads (read from WA cache + streaming)

* fix: simplify downloadMediaStream to use a single handle

instead of two handles (resultHandle + blobHandle) with disposal gaps,
get the blob handle directly from evaluateHandle and read metadata
via blobHandle.evaluate. This eliminates the intermediate resultHandle
entirely.

blobhandle is disposed in all exit paths: null metadata, evaluate
error, and generator finally.
This commit is contained in:
Adi1231234 2026-06-19 19:07:21 +03:00 • committed by GitHub
commit 4df15e58b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 175 additions and 76 deletions

View file

@ -1,3 +1,4 @@
const fs = require('fs');
const { Client, Location, Poll, List, Buttons, LocalAuth } = require('./index');
const client = new Client({
@ -233,6 +234,18 @@ client.on('message', async (msg) => {
Platform: ${info.platform}
`,
);
} else if (msg.body === '!streamdownload' && msg.hasMedia) {
const result = await msg.downloadMediaStream();
if (result) {
const filePath = `./${result.filename || 'download'}`;
const writeStream = fs.createWriteStream(filePath);
result.stream.pipe(writeStream);
writeStream.on('finish', () => {
msg.reply(
`Media saved to ${filePath} (${result.mimetype}, ${result.filesize} bytes)`,
);
});
}
} else if (msg.body === '!mediainfo' && msg.hasMedia) {
const attachmentData = await msg.downloadMedia();
msg.reply(`