foliojs / brotli.js

A JavaScript port of the Brotli compression algorithm, as used in WOFF2
500 stars 51 forks source link

Standalone decompressor for browsers #25

Open sheffieldnikki opened 5 years ago

sheffieldnikki commented 5 years ago

It would be very helpful to include a pre-built standalone decompressor (and compressor?) for use in browsers #2 , as not everyone is familiar with Node.js.

Here is a unbrotli.js and unbrotli.min.js for use in browsers: unbrotli.zip unbrotli.min.js is a 92Kb download, or 59Kb if Brotli-compressed by your web server. Much of that is the base64-encoded dictionary.

Called with:

unbrotli(buffer, [outSize])

I built it with the following commands (Ubuntu 16.04):

apt-get install nodejs npm
sed -i "s/dictionary-data/dictionary-browser/" dec/dictionary.js
ln -s /usr/bin/nodejs /usr/bin/node
npm install -g browserify
npm install base64-js
browserify decompress.js --standalone unbrotli -o unbrotli.js

(I couldn't get tinyify or uglify to run without errors, so I used a separate Javascript-minifier.)

ArthurZhou123 commented 3 years ago

I also got an error in use compress.js. And I built this compress.js with your steps.

Uncaught TypeError: Cannot read property 'slice' of null
    at encode.js:11
    at Object.<anonymous> (encode.js:11)
    at Object../node_modules/brotli/build/encode.js (encode.js:56)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object../node_modules/brotli/compress.js (compress.js:1)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Object../node_modules/brotli/index.js (index.js:1)
    at __webpack_require__ (bootstrap:784)
    at fn (bootstrap:150)
    at Module../src/actions/appActions.js (role-resource-constants.js:91)