How to unzip a file? #44
-
Hello 👋 I guess I'm doing something wrong but I copied the code you sent me here and it doesn't work. Here is my code: uz.onfile = (f) => {
console.log(f); // this prints the file object successfully
if (f.name == '') {
const decoder = new DecodeUTF8();
f.ondata = (err, data, final) => decoder.push(data, final);
decoder.ondata = (str, final) => {
// this throws the following error:
/*
browser.js:1532 Uncaught (in promise) TypeError: Cannot read property 'length' of undefined
at DecodeUTF8.push (browser.js:1532)
at Object.f.ondata (Loader.svelte:20)
at AsyncUnzipInflate.d.ondata (browser.js:2263)
at Inflate.ondata (browser.js:2162)
at Inflate.c (browser.js:1004)
at Inflate.push (browser.js:1014)
at AsyncUnzipInflate.push (browser.js:2175)
at Unzip.push (browser.js:2211)
at Unzip.push (browser.js:2311)
at Unzip.push (browser.js:2216)
*/
}
f.start();
}
}
const reader = file.stream().getReader();
while (true) {
const { done, value } = await reader.read();
if (done) {
uz.push(new Uint8Array(0), true);
break;
}
uz.push(value); // this throws an the following error:
/*
Loader.svelte:35 Uncaught (in promise) RangeError: Maximum call stack size exceeded
at strFromU8 (browser.js:1618)
at _loop_2 (browser.js:2242)
at Unzip.push (browser.js:2298)
at Unzip.push (browser.js:2311)
at Unzip.push (browser.js:2216)
at Unzip.push (browser.js:2311)
at Unzip.push (browser.js:2216)
at Unzip.push (browser.js:2311)
at Unzip.push (browser.js:2311)
at Unzip.push (browser.js:2216)
*/
} file is an object from a file input. Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 15 replies
-
Sorry, this was a bug. I've published v0.6.5 which fixes the first bug, but I haven't experienced the second one. Can you try the following code? If it throws no error, try your previous code and if it still fails, send me your ZIP file. If this code throws an error, tell me what browser, version, OS, etc. you are running. const uz = new Unzip();
uz.register(AsyncUnzipInflate)
const file = (await fetch('https://raw.githubusercontent.com/mrdoob/three.js/dev/examples/models/3mf/truck.3mf')).body;
uz.onfile = (f) => {
console.log(f); // this prints the file object successfully
if (f.name != '3D/3dmodel.model' && !f.name.includes('.png')) {
const decoder = new DecodeUTF8();
f.ondata = (err, data, final) => decoder.push(data, final)
decoder.ondata = (str, final) => {
console.log(f.name, str);
}
f.start();
}
}
const reader = file.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) {
uz.push(new Uint8Array(0), true);
break;
}
uz.push(value);
} Side note, I noticed you're running the unminified build. Assuming you're using a CDN, make sure to use the CDN instructions in the README when running for production because those offer much less bundle size. If you want to get the app working ASAP, you can try using the JSZip instructions I gave you, though performance should be an order of magnitude faster with |
Beta Was this translation helpful? Give feedback.
Sorry, this was a bug. I've published v0.6.5 which fixes the first bug, but I haven't experienced the second one. Can you try the following code? If it throws no error, try your previous code and if it still fails, send me your ZIP file. If this code throws an error, tell me what browser, version, OS, etc. you are running.