feat: support big file downloads (read from WA cache + streaming)#201697
Open
Adi1231234 wants to merge 2 commits intowwebjs:mainfrom
Open
feat: support big file downloads (read from WA cache + streaming)#201697Adi1231234 wants to merge 2 commits intowwebjs:mainfrom
Adi1231234 wants to merge 2 commits intowwebjs:mainfrom
Conversation
a456c06 to
c22720f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
downloadMediare-downloads and decrypts media from WhatsApp's CDN on every call, even though the data is already sitting decrypted in the browser's memory. It also loads the entire file into a single base64 string, so a 25MB PDF becomes ~33MB in one allocation with no way to process it in chunks.This PR fixes both problems:
Read from WhatsApp's own caches instead of re-downloading
When WhatsApp Web resolves a media message, it stores the result in
InMemoryMediaBlobCache(250MB LRU pool, no per-file limit) andmediaObject.mediaBlob. This PR reads directly from those caches instead of going throughdownloadAndMaybeDecryptand the CDN. For themediaBlobpath,OpaqueData.forceToBlob()returns the internal Blob directly without copying.Add
downloadMediaStream()for large filesReturns a Node.js
Readablestream that reads the Blob in chunks viaevaluateHandle+blob.slice(), so the full file never sits in Node.js memory at once. Chunk size defaults to 10MB and is configurable.The cache-reading logic is extracted into a shared
window.WWebJS.resolveMediaBlob(msgId)utility used by both methods.Other changes: added
*.d.tsto.eslintignore, added TypeScript interfaces for the new API, added!streamdownloadexample command, fixeddownloadMediareturn type to include| undefined.Testing Summary
Test Details
Tested with images, videos, documents and audio messages across multiple accounts. Verified that cached media is read correctly and that streaming works for files up to 924MB. Confirmed
forceToBlob()returns the internal Blob without copying via memory profiling.Environment
Type of Change
Checklist
npm test).index.d.ts) have been updated if necessary.example.js) / documentation have been updated if applicable.