-
Is there a limitation on the size of files to decompress in the browser? I'm testing The problem starts with files around 200MB deflated (~2.1GB inflated) where I get the following error:
The error happens in the decompress step, a sample code looks like this:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
There's a hard limit on how big a single typed array can be. 2.1 GB is roughly the 231 byte limit that exists in all browsers for all typed arrays. Remember that you're housing 2.1 GB of data in memory at once. Your use seems perfect for streaming the data in one chunk at a time. let reader = new FileReader();
reader.onload = function(event) {
const buffer = new Uint8Array(event.target.result);
let totalLines = 0;
const strm = new fflate.AsyncDecompress((err, dat) => {
// If this is all standard ASCII:
const stringContent = fflate.strFromU8(dat);
totalLines += stringContent.split('\n').length;
});
let i = 0;
for (; i < buffer.length - 512000; i += 512000) {
strm.push(buffer.slice(i, i + 512000));
}
strm.push(buffer.slice(i), true);
});
reader.readAsArrayBuffer(file); Memory usage will cap out at 512 kB with this, and the decompression should work up to 2GB compressed files. After that, you'll need to stream the data in as well. |
Beta Was this translation helpful? Give feedback.
-
I wanted to give an update to this with the latest version of const stream = file.stream();
const reader = stream.getReader();
const utf8Stream = new fflate.DecodeUTF8((str, final) => {
// This is where your string data will arrive
console.log(str, str.split('\n'));
});
const dcmpStream = new fflate.AsyncDecompress((dat, final) => {
// Chain streams
utf8Stream.push(dat, final);
});
reader.read().then(({value, done}) => {
if (done) dcmpStream.push(new Uint8Array(0), true);
else dcmpStream.push(value);
}) This is much higher performance than even your previous solution because at no point in time is more than 64kB of memory used. For context, your original solution failed because it was over 2GB, my previous solution used 200MB. Hope this helps! |
Beta Was this translation helpful? Give feedback.
There's a hard limit on how big a single typed array can be. 2.1 GB is roughly the 231 byte limit that exists in all browsers for all typed arrays. Remember that you're housing 2.1 GB of data in memory at once.
Your use seems perfect for streaming the data in one chunk at a time.