Skip to content

Instantly share code, notes, and snippets.

@coryvirok
Created October 16, 2012 02:53

Revisions

  1. coryvirok renamed this gist Oct 16, 2012. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions hrmmm → hrmmm.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    ```javascript
    var zlib = require('zlib');

    var plaintext = 'Hello World';
    @@ -23,4 +22,3 @@ compressor.on('end', function() {
    console.log(decompressedData.join(''));
    });
    });
    ```
  2. coryvirok revised this gist Oct 16, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion hrmmm
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    ```javascript
    var zlib = require('zlib');

    var plaintext = 'Hello World';
    @@ -21,4 +22,5 @@ compressor.on('end', function() {
    decompressor.on('end', function() {
    console.log(decompressedData.join(''));
    });
    });
    });
    ```
  3. coryvirok created this gist Oct 16, 2012.
    24 changes: 24 additions & 0 deletions hrmmm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    var zlib = require('zlib');

    var plaintext = 'Hello World';
    var compressedData = [];

    var compressor = zlib.createGzip();
    compressor.write(plaintext);
    compressor.end();

    compressor.on('data', function(d) { compressedData.push(d);});
    compressor.on('end', function() {
    var b64CompressedData = new Buffer(compressedData.join('')).toString('base64');
    var b64CompressedBuf = new Buffer(b64CompressedData, 'base64');

    var decompressedData = [];
    var decompressor = zlib.createGunzip();
    decompressor.write(b64CompressedBuf);
    decompressor.end();
    decompressor.on('data', function(d) { decompressedData.push(d); });
    decompressor.on('error', function(e) { console.error('error: ' + e); });
    decompressor.on('end', function() {
    console.log(decompressedData.join(''));
    });
    });