3 ms·
Is the Brotli compression done in the browser? If so, can you give some insight how this is done?
by jansan 4y ago
Is the Brotli compression done in the browser? If so, can you give some insight how this is done?
- Ndymium 4y agoYep, it is! You can find the sources on GitLab[0]. The compression is done using brotli-wasm[1]. The entry point to the compression is the syncCompress[2] function, which converts the data to UTF-8, adds the needed header bytes, and then compresses using brotli-wasm. Decompression is done in a streaming way in streamDecompress[3]. This is to avoid zip bomb attacks, where even a short URL could decompress to gigabytes of data, locking the browser. Thankfully brotli-wasm had streaming decompression builtin, I just had to write the wrapper code to update the text content and the status bar in the UI. You can find the brotli-wasm code I'm using in the vendor folder[4], there is a JS wrapper and then the WASM code (both are straight from brotli-wasm). [0] https://gitlab.com/Nicd/t https://gitlab.com/Nicd/t [1] https://github.com/httptoolkit/brotli-wasm https://github.com/httptoolkit/brotli-wasm [2] https://gitlab.com/Nicd/t/-/blob/05e587b0183ff80b1c6e050b5d30f375330572ec/tahnaroskakori.js#L196 https://gitlab.com/Nicd/t/-/blob/05e587b0183ff80b1c6e050b5d3... [3] https://gitlab.com/Nicd/t/-/blob/05e587b0183ff80b1c6e050b5d30f375330572ec/tahnaroskakori.js#L223 https://gitlab.com/Nicd/t/-/blob/05e587b0183ff80b1c6e050b5d3... [4] https://gitlab.com/Nicd/t/-/tree/05e587b0183ff80b1c6e050b5d30f375330572ec/vendor https://gitlab.com/Nicd/t/-/tree/05e587b0183ff80b1c6e050b5d3...