You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
console.log(textDecoder.decode(decompressedData)) // Prints 'some input'
63
+
// console.log(Buffer.from(decompressedData).toString('utf8')); // Prints 'some input' with Buffer polyfill
54
64
```
55
65
56
-
The package itself has no runtime dependencies, but you will need a [browser Buffer polyfill](https://www.npmjs.com/package/browserify-zlib)for the above example code, or you can do the same using TextEncoder/Decoder instead if you prefer.
66
+
The package itself has no runtime dependencies, you will need [browser Buffer polyfill](https://www.npmjs.com/package/browserify-zlib)if you prefer using `Buffer` over using `TextEncoder/TextDecoder`.
57
67
58
-
If you want to support node & browsers with the same code, you can use the `await` form with the default export everywhere.
68
+
#### In browser with streams:
69
+
```
70
+
import brotliPromise from 'brotli-wasm' // Import the default export
71
+
72
+
const brotli = await brotliPromise // Import is async in browsers due to wasm requirements!
73
+
74
+
const input = 'some input'
75
+
76
+
const inputStream = new ReadableStream({
77
+
start (controller) {
78
+
controller.enqueue(input)
79
+
controller.close()
80
+
}
81
+
})
82
+
const textEncoderStream = new TextEncoderStream()
83
+
const compressStream = new brotli.CompressStream()
0 commit comments