Code Monkey home page Code Monkey logo

lzw-stream's Introduction

lzw-stream

A streaming LZW encoder and decoder in JavaScript

Usage

Install using npm:

npm install lzw-stream

Pipe data to it:

var LZWDecoder = require('lzw-stream/decoder');
var LZWEncoder = require('lzw-stream/encoder');
var fs = require('fs');

fs.createReadStream('in.txt')
  .pipe(new LZWEncoder)
  .pipe(new LZWDecoder)
  .pipe(fs.createWriteStream('out.txt'));

That example will produce a file out.txt that is identical to in.txt. Not very useful, but it illustrates how to use both the encoder and decoder. Check out the Node stream docs for more info on streams.

dataSize

There is a dataSize option for both the encoder and decoder, passed in as an argument to the constructor, which is the number of bits in each element of the input. It is set to 8 (or 1 byte) by default, since all elements in a buffer are 8 bits. If you knew you had ASCII text, for example, you could set it to 7 since all ASCII characters can be represented in 7 bits. This would lead to better compression. On the other hand, if your elements are larger than 8 bits, then dataSize should be set to that size. Most of the time, however, you should just use the default.

Browser Usage

To use lzw-stream in the browser, check out Browserify, which builds Node-style modules for browser usage.

License

MIT

lzw-stream's People

Contributors

devongovett avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

thomas-git

lzw-stream's Issues

Decoding / Encoding failure

This is old code. I hope you can help :

Here is a test file (2 bitmaps) and result after compress/decompress

test.zip

There is obviously an error somewhere but I don't know where. Any clue ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.