Lightweight polyfill/ponyfill for the Compression Streams API
npm install compression-streams-polyfillInstall:
``sh`
npm i compression-streams-polyfill # or yarn add, or pnpm add
Import:
`js`
import 'compression-streams-polyfill';
// CompressionStream and DecompressionStream are now available
If your environment doesn't support ES Modules:
`js`
require('compression-streams-polyfill');
If you want to load from a CDN in the browser:
`html`
This polyfill is almost perfectly spec-compliant. Nonetheless, if you'd like to avoid adding CompressionStream and DecompressionStream to the global scope, you can use the ponyfill.
Note that you must supply your own TransformStream implementation to use the ponyfill (though TransformStream is available in most modern browsers). `js
import { makeCompressionStream, makeDecompressionStream } from 'compression-streams-polyfill/ponyfill';
// If you'd like to also ponyfill TransformStream:
// import { TransformStream } from 'web-streams-polyfill/ponyfill';
const CompressionStream = makeCompressionStream(TransformStream);
const DecompressionStream = makeDecompressionStream(TransformStream);
`
and DecompressionStream. The CompressionStream` polyfill also yields similar compression ratios to the native implementation.The polyfill's full bundle size is about 17kB minified, or 7kB gzipped.