1
0
Fork 0
mirror of https://github.com/codedread/bitjs synced 2025-10-03 17:49:16 +02:00

Update docs for gunzip

This commit is contained in:
Jeff Schiller 2024-02-04 21:11:17 -08:00
parent 5facf91dba
commit 440478c520
2 changed files with 14 additions and 13 deletions

View file

@ -8,8 +8,8 @@ A set of dependency-free JavaScript modules to work with binary data in JS (usin
[Typed Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)). [Typed Arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)).
Includes: Includes:
* bitjs/archive: Decompressing files (unzip, unrar, untar) in JavaScript, implemented as Web * bitjs/archive: Decompressing files (unzip, unrar, untar, gunzip) in JavaScript, implemented as
Workers where supported, and allowing progressive unarchiving while streaming. Web Workers where supported, and allowing progressive unarchiving while streaming.
* bitjs/codecs: Get the codec info of media containers in a ISO RFC6381 MIME type string. * bitjs/codecs: Get the codec info of media containers in a ISO RFC6381 MIME type string.
* bitjs/file: Detect the type of file from its binary signature. * bitjs/file: Detect the type of file from its binary signature.
* bitjs/image: Parsing GIF, JPEG, PNG. Conversion of WebP to PNG or JPEG. * bitjs/image: Parsing GIF, JPEG, PNG. Conversion of WebP to PNG or JPEG.
@ -49,7 +49,7 @@ const { getFullMIMEString } = await import('@codedread/bitjs');
### bitjs.archive ### bitjs.archive
This package includes objects for decompressing and compressing binary data in popular archive This package includes objects for decompressing and compressing binary data in popular archive
formats (zip, rar, tar). Here is a simple example of unrar: formats (zip, rar, tar, gzip). Here is a simple example of unrar:
#### Decompressing #### Decompressing

View file

@ -1,14 +1,15 @@
# bitjs.archive # bitjs.archive
This package includes objects for unarchiving binary data in popular archive formats (zip, rar, tar) This package includes objects for unarchiving binary data in popular archive formats (zip, rar,
providing unzip, unrar and untar capabilities via JavaScript in the browser or various JavaScript tar, gzip) providing unzip, unrar, untar, gunzip capabilities via JavaScript in the browser or
runtimes (node, deno, bun). various JavaScript runtimes (node, deno, bun).
A prototype version of a compressor that creates Zip files is also present. A compressor that creates Zip files is also present.
The decompression / compression happens inside a Web Worker, if the runtime supports it (browsers, The decompression / compression happens inside a Web Worker, if the runtime supports it (browsers,
deno). The library uses native decompression, if supported by the browser deno). The library uses native decompression, if supported by the browser
(via [DecompressionStream](https://developer.mozilla.org/en-US/docs/Web/API/DecompressionStream/DecompressionStream)), and falls back to JavaScript implementations otherwise. (via [DecompressionStream](https://developer.mozilla.org/en-US/docs/Web/API/DecompressionStream/DecompressionStream)),
and falls back to JavaScript implementations otherwise.
The API is event-based, you will want to subscribe to some of these events: The API is event-based, you will want to subscribe to some of these events:
* 'progress': Periodic updates on the progress (bytes processed). * 'progress': Periodic updates on the progress (bytes processed).
@ -31,7 +32,7 @@ etc.
```javascript ```javascript
import { Unzipper } from './bitjs/archive/decompress.js'; import { Unzipper } from './bitjs/archive/decompress.js';
const unzipper = new Unzipper(zipFileArrayBuffer); const unzipper = new Unzipper(zipFileArrayBuffer);
unzipper.addEventListener('extract', (evt) => { unzipper.onExtract(evt => {
const {filename, fileData} = evt.unarchivedFile; const {filename, fileData} = evt.unarchivedFile;
console.log(`unzipped ${filename} (${fileData.byteLength} bytes)`); console.log(`unzipped ${filename} (${fileData.byteLength} bytes)`);
// Do something with fileData... // Do something with fileData...
@ -40,7 +41,7 @@ etc.
unzipper.start(); unzipper.start();
``` ```
`start()` is an async method that resolves a `Promise` when the unzipping is complete, so you can `start()` is an async method that resolves a `Promise` when the decompression is complete, so you can
`await` on it, if you need to. `await` on it, if you need to.
### Progressive unzipping ### Progressive unzipping
@ -65,14 +66,14 @@ constructor, and send subsequent `ArrayBuffers` using the `update()` method.
### getUnarchiver() ### getUnarchiver()
If you don't want to bother with figuring out if you have a zip, rar, or tar file, you can use the If you don't want to bother with figuring out if you have a zip, rar, tar, or gz file, you can use
convenience method `getUnarchiver()`, which sniffs the bytes for you and creates the appropriate the convenience method `getUnarchiver()`, which sniffs the bytes for you and creates the appropriate
unarchiver. unarchiver.
```javascript ```javascript
import { getUnarchiver } from './bitjs/archive/decompress.js'; import { getUnarchiver } from './bitjs/archive/decompress.js';
const unarchiver = getUnarchiver(anArrayBuffer); const unarchiver = getUnarchiver(anArrayBuffer);
unarchive.addEventListener('extract', () => {...}); unarchiver.onExtract(evt => {...});
// etc... // etc...
unarchiver.start(); unarchiver.start();
``` ```