commit cca513a0382f01a2da45e9711d8d4ca350a96a4f Author: Google Code Exporter Date: Tue Apr 19 20:04:54 2016 -0400 Migrating wiki contents from Google Code diff --git a/Archive.md b/Archive.md new file mode 100644 index 0000000..1433e38 --- /dev/null +++ b/Archive.md @@ -0,0 +1,46 @@ +# Introduction # + +The plan is to migrate decode.js, unzip.js, unrar.js and untar.js from kthoom into BitJS. The code is a little messy right now and not very easily extractable in library form, so the following is a design proposal for the API. + +# Details # + +This code will live in the namespace: **bitjs.archive** + +## UnarchiveEvent ## + +The first thing to note is that decode.js currently depends on being in its own worker thread. Even though this is probably the preferred means of using the unarchiving code, I'd really like the code to not depend upon this (i.e. it should be possible to untar in the main window JS context). + +The right way to handle this is to define events (**bitjs.archive.UnarchiveEvent**) that the unarchiving code sends out to listeners. Some UnarchiveEvent types: + + * Start Event + * Progress Event - sends progress update information + * Extract Event - sends the extracted file + * Finish Event + * Error Event + +Client code would then listen for unarchiving events and act accordingly. For example, the event listeners in a [web worker](http://dev.w3.org/html5/workers/) could postMessage(). + +## UnarchivedFile ## + +We'll define a **bits.archive.UnarchivedFile** object that has the following two properites: + + * filename - returns the full filename + * fileData - returns a TypedArray representing the file's binary contents + +These objects will be returned in Extracted File Events to the client code's listener. + +## Unarchiver ## + +We will define a base abstract class called **bitjs.archive.Unarchiver**: + + * the constructor accepts a [Typed Array](http://www.khronos.org/registry/typedarray/specs/latest/) + * an **addEventListener()** method + * a **removeEventListener()** method + * a **run()** method, which will start the unarchive process and return immediately + * an abstract **run()** method which must be implemented by a subclass + +## Unzipper, Unrarrer, Untarrer ## + +We will have three concrete subclasses of Unarchiver, one for each supported file format: zip, rar, tar that will each live in separate files. This helps save on JS load time/memory, since the web application only needs to include the files it needs. + +**NOTE**: kthoom's file sniffing will necessarily have to be done first (using a bitjs.io stream, naturally) to determine which Unarchiver subclass to create and kick off. \ No newline at end of file diff --git a/BitStream.md b/BitStream.md new file mode 100644 index 0000000..2a04b8f --- /dev/null +++ b/BitStream.md @@ -0,0 +1,7 @@ +# Introduction # + +TODO: Add content here. + +# Details # + +TODO: Add content here. \ No newline at end of file diff --git a/ByteBuffer.md b/ByteBuffer.md new file mode 100644 index 0000000..2a04b8f --- /dev/null +++ b/ByteBuffer.md @@ -0,0 +1,7 @@ +# Introduction # + +TODO: Add content here. + +# Details # + +TODO: Add content here. \ No newline at end of file diff --git a/ByteStream.md b/ByteStream.md new file mode 100644 index 0000000..2a04b8f --- /dev/null +++ b/ByteStream.md @@ -0,0 +1,7 @@ +# Introduction # + +TODO: Add content here. + +# Details # + +TODO: Add content here. \ No newline at end of file diff --git a/ProjectHome.md b/ProjectHome.md new file mode 100644 index 0000000..85b7e70 --- /dev/null +++ b/ProjectHome.md @@ -0,0 +1,29 @@ +## Introduction ## + +A set of tools to handle binary data in JS (using [Typed Arrays](http://www.khronos.org/registry/typedarray/specs/latest/)). + +## 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 unarchive code depends on browser support of [Web Workers](http://dev.w3.org/html5/workers/). See the [design doc](http://code.google.com/p/bitjs/wiki/Archive). + +``` +function updateProgressBar(e) { ... update UI element ... } +function displayZipContents(e) { ... display contents of the extracted zip file ... } + +var unzipper = new bitjs.archive.Unzipper(zipFileArrayBuffer); +unzipper.addEventListener("progress", updateProgressBar); +unzipper.addEventListener("finish", displayZipContents); +unzipper.start(); +``` \ No newline at end of file