Permalink
Browse files

Get node-compress working with node 0.6.x

  • Loading branch information...
1 parent 12cd77f commit 4492d851be8fb2ec452f3a41eca01e348d07a439 @orlandov orlandov committed Mar 15, 2012
Showing with 34 additions and 39 deletions.
  1. +0 −2 .npmignore
  2. +8 −9 demo/bzstreams-demo.js
  3. +9 −9 demo/demo.js
  4. +5 −6 demo/pipe-demo.js
  5. +8 −8 demo/streams-demo.js
  6. +1 −1 lib/compress/index.js
  7. +2 −1 src/gzip.cc
  8. +1 −3 src/zlib.h
View
@@ -1,3 +1 @@
build
-wscript
-src
View
@@ -21,7 +21,7 @@
*/
var compress=require("../lib/compress");
-var sys=require("sys");
+var util=require("util");
var posix=require("fs");
var Buffer = require('buffer').Buffer;
@@ -37,7 +37,7 @@ function bind(fun, self) {
function doCompress(compressor, continuation) {
- sys.puts('Making compression requests...');
+ console.log('Making compression requests...');
var output = '';
compressor.setInputEncoding('utf8');
compressor.setEncoding('binary');
@@ -46,22 +46,22 @@ function doCompress(compressor, continuation) {
}).addListener('error', function(err) {
throw err;
}).addListener('end', function() {
- sys.puts('Compressed length: ' + output.length);
+ console.log('Compressed length: ' + output.length);
continuation(output);
});
compressor.write("My data that needs ");
compressor.write("to be compressed. 01234567890.");
compressor.close();
- sys.puts('Requests done.');
+ console.log('Requests done.');
}
function doDecompress(decompressor, input) {
var d1 = input.substr(0, 25);
var d2 = input.substr(25);
- sys.puts('Making decompression requests...');
+ console.log('Making decompression requests...');
var output = '';
decompressor.setInputEncoding('binary');
decompressor.setEncoding('utf8');
@@ -70,16 +70,15 @@ function doDecompress(decompressor, input) {
}).addListener('error', function(err) {
throw err;
}).addListener('end', function() {
- sys.puts('Decompressed length: ' + output.length);
- sys.puts('Raw data: ' + output);
+ console.log('Decompressed length: ' + output.length);
+ console.log('Raw data: ' + output);
});
decompressor.write(d1);
decompressor.write(d2);
decompressor.close();
- sys.puts('Requests done.');
+ console.log('Requests done.');
}
doCompress(new compress.BzipStream(),
bind(doDecompress, null, new compress.BunzipStream()));
-
View
@@ -22,7 +22,7 @@
var compress=require("../lib/compress");
var events=require('events');
-var sys=require("sys");
+var util=require("util");
var posix=require("fs");
var Buffer = require('buffer').Buffer;
@@ -48,7 +48,7 @@ function seq() {
});
}
}
-sys.inherits(seq, events.EventEmitter);
+util.inherits(seq, events.EventEmitter);
function createBuffer(str, enc) {
enc = enc || 'utf8';
@@ -61,28 +61,28 @@ function createBuffer(str, enc) {
// Create gzip stream
var gzip = new compress.Gzip(4);
-sys.puts('gzip created');
+console.log('gzip created');
// Pump data to be compressed
var gzdata1, gzdata2, gzdata3;
var compression = new seq(
function(state, continuation){
gzip.write(createBuffer("My data that needs "), function(err, data) {
- sys.puts("Compressed size: " + data.length);
+ console.log("Compressed size: " + data.length);
continuation(err, state + data.toString('binary'));
});
},
function(state, continuation){
gzip.write(createBuffer("to be compressed. 01234567890."), function(err, data) {
- sys.puts("Compressed size: " + data.length);
+ console.log("Compressed size: " + data.length);
continuation(err, state + data.toString('binary'));
});
},
function(state, continuation){
gzip.close(function(err, data) {
- sys.puts("Last bit: " + data.length);
+ console.log("Last bit: " + data.length);
data = state + data.toString('binary');
- sys.puts("Total compressed size: " + data.length);
+ console.log("Total compressed size: " + data.length);
continuation(err, data);
});
}
@@ -119,9 +119,9 @@ function doCompress() {
}
function doDecompress(data) {
- sys.puts('Decompressing');
+ console.log('Decompressing');
decompression.addListener('success', function(data){
- sys.puts(data.output);
+ console.log(data.output);
});
decompression.start({input:[data.substr(0,25), data.substr(25)],output:''});
View
@@ -20,7 +20,7 @@
* IN THE SOFTWARE.
*/
-var sys = require('sys');
+var util = require('util');
var compress=require("../lib/compress");
var Stream = require('stream').Stream;
@@ -34,19 +34,18 @@ Stream.prototype.pipe.call(gzipper, gunzipper);
Stream.prototype.pipe.call(gunzipper, process.stdout, {end:false});
gunzipper.once('end', function flushStdout() {
- sys.puts("-- all done");
- process.stdout.end();
+ console.log("-- all done");
});
//console.log({gzipper:gzipper, gunzipper:gunzipper, stdout:process.stdout});
-sys.puts("-- starting");
+console.log("-- starting");
gzipper.write(new Buffer("Here is the first chunk.\n"));
setTimeout(function() {
- sys.puts("-- tick");
+ console.log("-- tick");
gzipper.write(new Buffer("Here is the next chunk.\n"));
setTimeout(function() {
- sys.puts("-- tock");
+ console.log("-- tock");
gzipper.write(new Buffer("Here is the final chunk.\n"));
gzipper.end();
}, 500);
View
@@ -21,7 +21,7 @@
*/
var compress=require("../lib/compress");
-var sys=require("sys");
+var util=require("util");
var posix=require("fs");
var Buffer = require('buffer').Buffer;
@@ -37,7 +37,7 @@ function bind(fun, self) {
function doCompress(compressor, continuation) {
- sys.puts('Making compression requests...');
+ console.log('Making compression requests...');
var output = '';
compressor.setInputEncoding('utf8');
compressor.setEncoding('binary');
@@ -46,22 +46,22 @@ function doCompress(compressor, continuation) {
}).addListener('error', function(err) {
throw err;
}).addListener('end', function() {
- sys.puts('Compressed length: ' + output.length);
+ console.log('Compressed length: ' + output.length);
continuation(output);
});
compressor.write("My data that needs ");
compressor.write("to be compressed. 01234567890.");
compressor.close();
- sys.puts('Requests done.');
+ console.log('Requests done.');
}
function doDecompress(decompressor, input) {
var d1 = input.substr(0, 25);
var d2 = input.substr(25);
- sys.puts('Making decompression requests...');
+ console.log('Making decompression requests...');
var output = '';
decompressor.setInputEncoding('binary');
decompressor.setEncoding('utf8');
@@ -70,13 +70,13 @@ function doDecompress(decompressor, input) {
}).addListener('error', function(err) {
throw err;
}).addListener('end', function() {
- sys.puts('Decompressed length: ' + output.length);
- sys.puts('Raw data: ' + output);
+ console.log('Decompressed length: ' + output.length);
+ console.log('Raw data: ' + output);
});
decompressor.write(d1);
decompressor.write(d2);
decompressor.close();
- sys.puts('Requests done.');
+ console.log('Requests done.');
}
View
@@ -23,7 +23,7 @@
var events = require('events');
var Buffer = require('buffer').Buffer;
var assert = require('assert');
-var bindings = require('./compress-bindings');
+var bindings = require('../../build/Release/compress-bindings');
function removed(str) {
return function() {
View
@@ -22,7 +22,6 @@
*/
#include <node.h>
-#include <node_events.h>
#include <node_buffer.h>
#include <assert.h>
#include <string.h>
@@ -115,6 +114,7 @@ const char GzipUtils::VersionError[] = "Z_VERSION_ERROR: "
class GzipImpl {
friend class ZipLib<GzipImpl>;
+ public:
typedef GzipUtils Utils;
typedef GzipUtils::Blob Blob;
@@ -215,6 +215,7 @@ typedef ZipLib<GzipImpl> Gzip;
class GunzipImpl {
friend class ZipLib<GunzipImpl>;
+ public:
typedef GzipUtils Utils;
typedef GzipUtils::Blob Blob;
View
@@ -28,7 +28,6 @@
#include <new>
#include <node.h>
-#include <node_events.h>
#include <node_buffer.h>
#include <node_version.h>
#include <assert.h>
@@ -324,12 +323,11 @@ class ZipLib : ObjectWrap {
// Process requests queue.
// Executed in worker thread.
- static int DoProcess(eio_req *req) {
+ static void DoProcess(eio_req *req) {
Request *request = reinterpret_cast<Request*>(req->data);
//DEBUG_P("Processing [%p]", request);
Self *self = request->self();
self->DoProcess(request);
- return 0;
}
void DoProcess(Request *request) {

0 comments on commit 4492d85

Please sign in to comment.