File tree Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Expand file tree Collapse file tree 2 files changed +39
-2
lines changed Original file line number Diff line number Diff line change @@ -63,11 +63,45 @@ console.log(textDecoder.decode(decompressedData)); // Prints 'some input'
6363
6464You can also load it from a CDN like so:
6565``` javascript
66- let brotli = await import (" https://unpkg.com/brotli-wasm@1.3.1 /index.web.js?module" ).then (m => m .default );
66+ const brotli = await import (" https://unpkg.com/brotli-wasm@3.0.0 /index.web.js?module" ).then (m => m .default );
6767```
6868
6969The package itself has no runtime dependencies, although if you prefer using ` Buffer ` over using ` TextEncoder/TextDecoder ` you may want a [ browser Buffer polyfill] ( https://www.npmjs.com/package/browserify-zlib ) .
7070
71+ ##### Using an importmap
72+
73+ If you've installed ` brotli-wasm ` as an NPM package, you can load it from your ` node_modules ` subfolder:
74+
75+ ``` html
76+ <!-- index.html -->
77+ <!DOCTYPE html>
78+ <html lang =" en" >
79+ <head ></head >
80+ <body >
81+ <script type =" importmap" >
82+ {
83+ " imports" : {
84+ " brotli-wasm" : " /node_modules/brotli-wasm/index.web.js"
85+ }
86+ }
87+ </script >
88+ <script type =" module" src =" /main.js" ></script >
89+ </body >
90+ </html >
91+ ```
92+
93+ ``` javascript
94+ // main.js
95+ import brotliPromise from ' brotli-wasm' ;
96+ const brotli = await brotliPromise;
97+
98+ const input = ' some input' ;
99+ const uncompressedData = new TextEncoder ().encode (input);
100+ const compressedData = brotli .compress (uncompressedData);
101+ const decompressedData = brotli .decompress (compressedData);
102+ console .log (new TextDecoder ().decode (decompressedData)); // Prints 'some input'
103+ ```
104+
71105#### In browser with streams:
72106
73107``` javascript
Original file line number Diff line number Diff line change 11// In pure ESM web bundles, you must call init() and wait for the promised result before you can
22// call any module methods. To make that as easy as possible, this module directly exposes the
33// init() promise result, and returns the methods at the end of the promise.
4- import init , * as brotliWasm from "./pkg.web/brotli_wasm" ;
4+ // https://github.com/WICG/import-maps?tab=readme-ov-file#extension-less-imports
5+ // For usage with an importmap, it's convenient to add the ".js" extension here, because browsers
6+ // don't try to guess the file extension.
7+ import init , * as brotliWasm from "./pkg.web/brotli_wasm.js" ;
58export default init ( ) . then ( ( ) => brotliWasm ) ;
You can’t perform that action at this time.
0 commit comments