1
0
Fork 0
mirror of https://github.com/codedread/bitjs synced 2025-10-05 18:34:17 +02:00
No description
Find a file
2018-02-01 09:31:29 -08:00
archive Update readme for streaming and add a TODO for Issue #11 2018-02-01 09:31:29 -08:00
docs Update link in unrar doc to bitjs on github. 2017-02-21 18:24:17 -08:00
io Remove pushing and throwing errors from BitStream and update unit tests. Update unrar to use a ByteStream for the RAR file header (like unzip) 2018-01-30 00:16:38 -08:00
tests Remove pushing and throwing errors from BitStream and update unit tests. Update unrar to use a ByteStream for the RAR file header (like unzip) 2018-01-30 00:16:38 -08:00
LICENSE Accidentally didn't add the updated files. 2016-04-19 18:00:27 -07:00
README.md Update readme for streaming and add a TODO for Issue #11 2018-02-01 09:31:29 -08:00

bitjs: Binary Tools for JavaScript

Introduction

A set of tools to handle binary data in JS (using Typed Arrays).

Example Usage

bitjs.io

This namespace includes stream objects for reading and writing binary data at the bit and byte level: BitStream, ByteStream.

var bstream = new bitjs.io.BitStream(someArrayBuffer, true, offset, length);
var crc = bstream.readBits(12); // read in 12 bits as CRC, advancing the pointer
var flagbits = bstream.peekBits(6); // look ahead at next 6 bits, but do not advance the pointer

bitjs.archive

This namespace includes objects for unarchiving binary data in popular archive formats (zip, rar, tar) providing unzip, unrar and untar capabilities via JavaScript in the browser. The unarchiving actually happens inside a Web Worker.

var unzipper = new bitjs.archive.Unzipper(zipFileArrayBuffer);
unzipper.addEventListener('progress', updateProgress);
unzipper.addEventListener('extract', receiveOneFile);
unzipper.addEventListener('finish', displayZipContents);
unzipper.start();

function updateProgress(e) {
  // e.totalCompressedBytesRead has how many bytes have been unzipped so far
}

function receiveOneFile(e) {
  // e.unarchivedFile.filename: string
  // e.unarchivedFile.fileData: Uint8Array
}

function displayZipContents() {
  // Now sort your received files and show them or whatever...
}

function 

The unarchivers also support streaming, if you are receiving the zipped file from a slow place (a Cloud API, for instance). For example:

var unzipper = new bitjs.archive.Unzipper(anArrayBufferWithStartingBytes);
unzipper.addEventListener('progress', updateProgress);
unzipper.addEventListener('extract', receiveOneFile);
unzipper.addEventListener('finish', displayZipContents);
unzipper.start();
...
// after some time
unzipper.update(anArrayBufferWithMoreBytes);
...
// after some more time
unzipper.update(anArrayBufferWithYetMoreBytes);

Tests

Reference

  • UnRar: A work-in-progress description of the RAR file format.

History

This repository was automatically exported from my original repository on GoogleCode and then I cherry-picked some commits from antimatter15's fork. I've also fixed a bunch of bugs, added starter RarVM support, added tests and updated to ES6.