Permalink
Browse files

Added working examples for using the library.

refs #1
  • Loading branch information...
1 parent ab9c6b5 commit 7d61ca7e7fd094f2ed2e69941c9b03ea3502b053 @hiddentao committed May 19, 2012
Showing with 40 additions and 12 deletions.
  1. +40 −12 README.md
View
52 README.md
@@ -16,7 +16,7 @@ size.
Minified library size is only ~4KB (~2KB when gzipped).
-## How to use
+## Install for browser
The **index.html** file included contains a testing form for the algorithm as well as automated tests based
on predefined data which is good at catching boundary case errors.
@@ -25,28 +25,56 @@ To use the algorithm in your own projects include the **lzw-async.js** file usin
<script type="text/javascript" src="lzw-async.min.js"></script>
+
+## Install for node.js
+
+To use with node.js install the module:
+
+ $ npm install lzw-async
+
+
+## Examples
+
To compress call:
- LZWAsync.compress(...)
+ LZWAsync.compress({
+ input : "rawtext",
+ output : function(output) {
+ console.log(output);
+ }
+ });
To decompress call:
- LZWAsync.decompress(...)
+ LZWAsync.decompress({
+ input : "compressedtext",
+ output : function(output) {
+ console.log(output);
+ }
+ });
-## How to use with node.js
-To use with node.js install the module:
+To receive progress updates:
- $ npm install lzw-async
+ LZWAsync.compress({
+ input : "rawtext",
+ output : function(output) {
+ console.log(output);
+ },
+ progress: function (percent) {
+ console.log(percent + " % done");
+ }
+ });
-Note that when using it with node there is no `LZWAsync` namespace:
+If you already know which characters will appear in the raw input then you can tell LZWAsync to restrict the
+dictionary to only those characters, thereby improving the compression ratio:
- var lzw = require('lzw-async');
- lzw.compress({
- input : "test",
+ LZWAsync.compress({
+ input : "rawtext",
output : function(output) {
- console.log(output);
- }
+ console.log(output);
+ },
+ dict: 'abcdefghijklmnopqrstuvwxyz'
});

0 comments on commit 7d61ca7

Please sign in to comment.