How to save memory #392
-
First of all: Thanks a lot for this awesome, lightweight library! I implemented it similarily to the create file demo and got an issue that is reproducable on the demo as well: Using iOS Safari:
I guess it has to do with the maximum RAM a browser can occupy which is 384 MB on iOS Safari 15. Do you know of any workaround to that problem? Would it help to use the SplitDataReader class? I would appreciate any help! |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 4 replies
-
I don't have an iOS device and I was not able to reproduce the issue in the simulator bundled with Xcode. I guess the Origin Private File System API could help, see https://webkit.org/blog/12257/the-file-system-access-api-with-origin-private-file-system/. However it's a bit tricky to use because FileSystemFileHandle#createSyncAccessHandle is only available in a Worker. The |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick response! So your idea is to create a zip file on the device itself via the Private File System API and only upload it then? Not sure whether that would reduce memory usage though. I decided to remove zip.js on iOS completely and go for another approach so the browser does not have to save the same blob twice. As I have the same problem when using navigator.share with big files though, I simply won't allow files bigger than 200 MB on iOS. If you're interested where your project got implemented into: Peer to peer file sharing https://pairdrop.net/ (Repo) As this issue is not really zip.js specific I'll close it, thanks for helping though! |
Beta Was this translation helpful? Give feedback.
-
I did not know that you needed to upload the data. In this case, you just needed to write your own |
Beta Was this translation helpful? Give feedback.
-
I needed to create a zip file and send it in chunks via webrtc to another peer. Files in a FileList from a multifile input somehow did not crash the website but creating a zip from them did. A zip file created by a custom |
Beta Was this translation helpful? Give feedback.
-
Hey @gildas-lormeau, I'm getting back to this as I want to reduce the memory usage of my application once again. I'd appreciate if a lot if you could help me once again! Do I understand it right, that using the following snippet would not put the complete file in RAM or would I need to rewrite it to use streams to accomplish that? async function getDownloadUrlOfZipFile(files, onZipProgressCallback) {
const zipWriter = new zip.ZipWriter(new zip.BlobWriter("application/zip"), {
bufferedWrite: true,
level: 0
});
let bytesProcessed = 0;
for (let i = 0; i < files.length; i++) {
await zipWriter.add(
files[i].name,
new zip.BlobReader(files[i]),
{
onprogress: (progress) => onZipProgressCallback(bytesProcessed + progress)
}
);
bytesProcessed += files[i].size;
}
return URL.createObjectURL(await zipWriter.close());
} |
Beta Was this translation helpful? Give feedback.
I don't have an iOS device and I was not able to reproduce the issue in the simulator bundled with Xcode.
I guess the Origin Private File System API could help, see https://webkit.org/blog/12257/the-file-system-access-api-with-origin-private-file-system/. However it's a bit tricky to use because FileSystemFileHandle#createSyncAccessHandle is only available in a Worker. The
SplitDataReader
would not be useful. However you could create a split zip with by using a generator ofWriter
, it could help to save memory. There's a test showing how to use it here: https://github.com/gildas-lormeau/zip.js/blob/910cdf666382d5738a69c490b79483ce4b96df28/tests/all/test-split-zip.js and a similar demo here: …