Uncaught RangeError: Maximum call stack size exceeded #20
-
I have a working browser extension that use JSZip to create and read zip files. I want to migrate it to fflate but I have a problem while I'm trying to implement the library. I get this error inside the console
As you can see I need to loop an array of files and add each file to the archive before give it to the user. I'm using the async api, Is possible to have an example of how to manage this? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 5 replies
-
Check out demo site: https://101arrowz.github.io/fflate/ You cannot add function readFile(file: File) {
return new Promise<Uint8Array>((resolve, reject) => {
const reader = new FileReader();
reader.onloadend = () => {
resolve(new Uint8Array(reader.result as ArrayBuffer));
};
reader.onerror = reject;
reader.readAsArrayBuffer(file);
});
} Then you have to create archive structure, for example: const archiveStruct: AsyncZippable = {}
for (const file of files) {
const fileBuffer = await readFile(file);
archiveStruct[file.name] = fileBuffer;
} Then you can zip all files, like so: fflate.zip(
archiveStruct,
{ consume: true, level: 9 },
(err, out) => {
if (err) {
console.log("error", err);
return;
}
console.log(out); // this is your archive buffer
}
); |
Beta Was this translation helpful? Give feedback.
-
I've modified a bit the code because I'm not using typescript but it seems working fine. I've created a method to read each single file and replaced the forEach() loop with for() as you have suggested. Just the last thing, I need to read the file also if I want to unzip it's content? |
Beta Was this translation helpful? Give feedback.
-
Yes, you need to do the same process of |
Beta Was this translation helpful? Give feedback.
-
There is something that will not work in the libray, while in dev mode the code like the one provided will work without any problem, when I create the production build it will stop working. This is the error logged in console
The function
I don't know if this can be cause because webpack will minify all the imported files and the library stop working or because my vue method is async. Any suggestion about fixing? |
Beta Was this translation helpful? Give feedback.
Check out demo site: https://101arrowz.github.io/fflate/
You cannot add
File
object directly, you have to read files first. This is example withPromise
, so you can easily use it with async/await:Then you have to create archive structure, for example: