Home :: Utilities

Base64 Encoding

This is JavaScript object that converts an array of bytes into their base64 encoding representation.

To use this object, invoke Base64.encode(data) where data is an arrary of bytes. The base64 encoded data is returned as a string.

base64.zip

Bit Streams

These are a set of JavaScript objects that allow you to read and write bits from and to an array. There are two versions of each Reader and Writer since one can fill up the bits in a byte either from left-to-right or right-to-left.

Please note that these have not been thoroughly tested. I wrote these to support the Huffman coding objects seen below and as such only the MSB (most significant bit) versions have been used in any type of application.

bit_stream.zip

32-bit CRC

This is a JavaScript object that will calculate a 32-bit CRC for an array of bytes.

To use this object, invoke CRC32.getCRC(data, offset, count) where data is an array of bytes, offset is the starting array index where the CRC calculation should start, and count is the number of elements to process beginning from the offset. The return value is the 32-bit CRC for the data specified.

CRC32.zip

Huffman Coding

This is a set of JavaScript objects that compresses an array of bytes using Huffman coding. Likewise, routines are included to decompress a Huffman coding stream to an array of bytes

This library was being written as a part of a JS implementation of gzip. This has not been thoroughly tested.

The zip file below includes all files needed to use the Huffman coding objects, including the BitReaderMSB.js and BitWriterMSB.js mentioned above. A sample file is included which shows how to compress and decompress an array of bytes.

huffman.zip

Red-Black Trees

This is a fairly generic JavaScript implementation of a Red-Black Tree. These trees are a type of binary tree which remains fairly balanced when adding and removing nodes.

Simply add() or remove() objects from the tree. The only requirement is that your objects must define a compare method. This method must return the typical negative, zero, or positive value based on the relationship of the object and the one it is begin compared to. An example showing the usage is included in the zip file below.

Other methods include min(), max(), next(), and previous(). These methods allow you to iterate through the tree.

red_black_tree.zip

SVG into PDF

This is a command line utility (Perl) that embeds an SVG file within a PDF file. A new PDF document will be created for each SVG specified on the command line. Some simple examples are included. Special thanks to Niklas Gustavsson for the animated cursor example (warning: may crash on MacOS).

SVG in PDF

Please note that you will need Acrobat Reader 5 along with the ImageViewer 4.0 Plug-in to view SVG documents in PDF files.