If I have a .json.gz
file that I’d like to decompress, it currently requires code that looks something like this:
let stream = blob.stream().readable.pipeThrough(new DecompressionStream("gzip")).pipeThrough(new TextDecoderStream());
let reader = stream.getReader();
let jsonText = "";
while(1) {
let {value, done} = await reader.read();
if(value) jsonText += value;
if(done) break;
}
let json = JSON.parse(jsonText);
I’m sure there are ways to simplify this a bit, but unless I’m mistaken (which I could be), it’s still going to be a bit of a mess.
It would be lovely if that code could be replaced by something like this:
let jsonText = await blob.decompress("gzip").then(b => b.text());
let json = JSON.parse(jsonText);
In the above example, blob.decompress("gzip")
returns a Promise that resolves to a decompressed blob, but please ignore the specifics of the above syntax/API - the main point I’m intending to get across here is that decompression of blobs could/should be a simple one-liner.
Thoughts?