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'
63
63
64
64
You can also load it from a CDN like so:
65
65
``` 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 );
67
67
```
68
68
69
69
The 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 ) .
70
70
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
+
71
105
#### In browser with streams:
72
106
73
107
``` javascript
Original file line number Diff line number Diff line change 1
1
// In pure ESM web bundles, you must call init() and wait for the promised result before you can
2
2
// call any module methods. To make that as easy as possible, this module directly exposes the
3
3
// 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" ;
5
8
export default init ( ) . then ( ( ) => brotliWasm ) ;
You can’t perform that action at this time.
0 commit comments