There's no reason why you can't decompress a blob stored in react or javascript. You can decompress it and with Web-Assembly, you can do that it nearly native performance.
You can use pako library to do this job.
From it's documentation,
Decompress data with inflate/ungzip and options. Autodetect format via wrapper header by default.
Here is the sample code, with some json.gz
's picked randomly from github.
const urls = [
'https://raw.githubusercontent.com/NazarHarashchak/MobileBanking/9155a04a3ff064167537a7c32f9cca356a5c3ab4/FrontEnd/node_modules/.cache/eslint-loader/b3fa51dc9159babf532b97696dacb328bf0a70dc.json.gz',
'https://raw.githubusercontent.com/mongodb-university/mflix-python/d9667e709bd400f3d3dbd6e7f1474b3702d9d5fa/data/mflix/comments.metadata.json.gz',
'https://raw.githubusercontent.com/dump-sauraj/realme_rmx2185_dump964/3a9c42cac2977a13e43ca8bf1ff886fca730f158/system/system/etc/protolog.conf.json.gz'
]
async function exec(i = 0) {
console.group('file: ', i);
try {
// fetch file with CORS enabled
const res = await fetch(urls[i], {
mode: 'cors'
});
// convert to arrayBuffer for further processing
const buf = await res.arrayBuffer();
// or get blob using `await res.blob()`
// and convert blob to arrayBuffer using `await blob.arrayBuffer()`
console.log('input size: ', buf.byteLength);
// decompress file
const outBuf = pako.inflate(buf);
console.log('output size: ', outBuf.byteLength);
// convert arrayBuffer to string
const str = new TextDecoder().decode(outBuf);
// console.log('json string', str);
// print json object
console.log('json object', JSON.parse(str));
} catch (err) {
console.error('unable to decompress', err);
}
console.groupEnd('file: ', i);
}
async function init() {
for (let i in urls) await exec(i)
}
init()
<script src="https://cdnjs.cloudflare.com/ajax/libs/pako/2.0.3/pako.min.js" integrity="sha512-yJSo0YTQvvGOqL2au5eH0W4K/0FI0sTJuyHjiHkh0O31Lzlb814P0fDXtuEtzOj13lOBZ9j99BjqFx4ASz9pGA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
I tried several packages like wasm-flate, wasm-gzip, d5ly and pako but only pako had highest success rate. You can consider them if you feel so.
Edit: added code comments and disabled console.log
of full json string