Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,25 @@ unzip.push(data, true);

See the [documentation](https://github.com/101arrowz/fflate/blob/master/docs/README.md) for more detailed information about the API.

## Raw BZIP2 (.bz2)

`fflate` can also decompress raw `.bz2` files directly, outside of ZIP archives.

```js
const bz2Data = await fetch('/file.bz2').then(res => res.arrayBuffer());
const textData = fflate.bunzip2Sync(new Uint8Array(bz2Data));
const text = fflate.strFromU8(textData);
```

If you prefer the asynchronous API:

```js
fflate.bunzip2(new Uint8Array(bz2Data), (err, data) => {
if (err) throw err;
console.log(fflate.strFromU8(data));
});
```

## Bundle size estimates

The bundle size measurements for `fflate` on sites like Bundlephobia include every feature of the library and should be seen as an upper bound. As long as you are using tree shaking or dead code elimination, this table should give you a general idea of `fflate`'s bundle size for the features you need.
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@
"build:rewrite": "SC=rewriteBuilds npm run script",
"build:demo": "tsc --project tsconfig.demo.json && parcel build demo/index.html --no-cache --public-url \"./\" && SC=cpGHPages npm run script",
"build:docs": "typedoc --plugin typedoc-plugin-markdown --hideBreadcrumbs --readme none --disableSources --excludePrivate --excludeProtected --expandParameters --githubPages false --out docs/ src/index.ts",
"test": "TS_NODE_PROJECT=test/tsconfig.json uvu -b -r ts-node/register test",
"test": "node scripts/run-tests.cjs",
"test:zip": "node scripts/run-test-file.cjs test/3-zip.ts",
"test:bzip2": "node scripts/run-test-file.cjs test/7-bzip2.ts",
"prepack": "npm run build && npm run test"
},
"devDependencies": {
Expand Down
20 changes: 20 additions & 0 deletions scripts/run-test-file.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { spawnSync } = require('node:child_process');

const args = process.argv.slice(2);
if (!args.length) {
throw new Error('Usage: node scripts/run-test-file.cjs <test-file.ts>');
}

const env = {
...process.env,
TS_NODE_PROJECT: 'test/tsconfig.json',
TS_NODE_TRANSPILE_ONLY: '1'
};

const result = spawnSync(process.execPath, ['-r', 'ts-node/register', ...args], {
stdio: 'inherit',
env
});

if (result.error) throw result.error;
process.exit(result.status ?? 1);
18 changes: 18 additions & 0 deletions scripts/run-tests.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { spawnSync } = require('node:child_process');
const path = require('node:path');

const args = process.argv.slice(2);
const uvuBin = path.join(__dirname, '..', 'node_modules', 'uvu', 'bin.js');
const env = {
...process.env,
TS_NODE_PROJECT: 'test/tsconfig.json',
TS_NODE_TRANSPILE_ONLY: '1'
};

const result = spawnSync(process.execPath, [uvuBin, '-b', '-r', 'ts-node/register', ...(args.length ? args : ['test'])], {
stdio: 'inherit',
env
});

if (result.error) throw result.error;
process.exit(result.status ?? 1);
Loading