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:
parent
2dc9466fac
commit
4df15e58b9
4 changed files with 175 additions and 76 deletions
13
example.js
13
example.js
|
|
@ -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(`
|
||||
|
|
|
|||
Loading…
Reference in a new issue