Created
February 18, 2020 12:43
-
-
Save jimmywarting/5085682dc310ba34a42af19a4d735bfb to your computer and use it in GitHub Desktop.
native (de)compress in browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { compress, decompress } from 'zlib.js' | |
compr = await compress('hhhhheeeej'.repeat(200)).blob() | |
blob = await decompress(compr).blob() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const r = d => new Response(d) | |
// accepts all kind of data response can handle | |
// and returns a new Response from witch you can call blob, arraybuffer, json, text and .body (stream) | |
// optional type is 'deflate' | |
export default { | |
compress: (d, t = 'gzip') => r(r(d).body.pipeThrough(new CompressionStream(t))), | |
decompress: (d, t = 'gzip') => r(r(d).body.pipeThrough(new DecompressionStream(t))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment