Permalink
Browse files

updated infate(encoding) issue. updated filetest to use fs (not posix…

…), wscript to handle different os requirements (non-exhaustive), and added a package.json file
  • Loading branch information...
1 parent f27af24 commit c6f90964fa0c3d2ad09a74be8af75b2c90b45291 @Woodya committed Jun 5, 2011
Showing with 69 additions and 29 deletions.
  1. +1 −1 compress.cc
  2. +27 −26 filetest.js
  3. +23 −0 package.json
  4. +18 −2 wscript
View
@@ -323,7 +323,7 @@ class Gunzip : public EventEmitter {
HandleScope scope;
enum encoding enc = ParseEncoding(args[1]);
- ssize_t len = DecodeBytes(args[0], enc);
+ ssize_t len = DecodeBytes(args[0], BINARY);
if (len < 0) {
Local<Value> exception = Exception::TypeError(String::New("Bad argument"));
View
@@ -1,41 +1,42 @@
-var compress=require("./compress");
-var sys=require("sys");
-var posix=require("posix");
+var compress = require("./compress");
+var sys = require("sys");
+var fs = require("fs");
// Read in our test file
-var data=posix.cat("filetest.js", encoding="binary").wait();
-sys.puts("Got : "+data.length);
+var testfile = process.argv[2] || "filetest.js";
+var enc = process.argv[3] || 'binary';
+var data = fs.readFileSync(testfile, enc);
+sys.puts("Got : " + data.length);
// Set output file
-var fd = posix.open("filetest.js.gz", process.O_WRONLY | process.O_TRUNC | process.O_CREAT, 0644).wait();
-sys.puts("Openned file");
+var fd = fs.openSync(testfile + ".gz", "w", 0644);
+sys.puts("File opened");
// Create gzip stream
-var gzip=new compress.Gzip;
+var gzip = new compress.Gzip;
gzip.init();
// Pump data to be compressed
-gzdata=gzip.deflate(data, "binary"); // Do this as many times as required
-sys.puts("Compressed size : "+gzdata.length);
-posix.write(fd, gzdata, encoding="binary").wait();
+var gzdata = gzip.deflate(data, enc); // Do this as many times as required
+sys.puts("Compressed size : " + gzdata.length);
+fs.writeSync(fd, gzdata, null, "binary");
// Get the last bit
-gzlast=gzip.end();
-sys.puts("Last bit : "+gzlast.length);
-posix.write(fd, gzlast, encoding="binary").wait();
-posix.close(fd).wait();
+var gzlast = gzip.end();
+sys.puts("Last bit : " + gzlast.length);
+fs.writeSync(fd, gzlast, null, "binary");
+fs.closeSync(fd);
sys.puts("File closed");
// See if we can uncompress it ok
-var gunzip=new compress.Gunzip;
+var gunzip = new compress.Gunzip;
gunzip.init();
-var testdata = posix.cat("filetest.js.gz", encoding="binary").wait();
-sys.puts("Test opened : "+testdata.length);
-sys.puts(gunzip.inflate(testdata, "binary").length);
-gunzip.end();
-
-
-
-
-
-
+var testdata = fs.readFileSync(testfile + ".gz", "binary");
+sys.puts("Test opened : " + testdata.length);
+var inflated = gunzip.inflate(testdata, enc);
+sys.puts("GZ.inflate.length: " + inflated.length);
+sys.puts("GZ.end.length: " + gunzip.end().length);
+
+if (data.length != inflated.length) {
+ sys.puts('error! input/output lengths do not match');
+}
View
@@ -0,0 +1,23 @@
+{
+ "name": "node-compress",
+ "description": "streaming gzip/gunzip for node, required libz",
+ "homepage" : "http://waveto.github.com/node-compress",
+ "bugs" : { "web" : "http://github.com/waveto/node-compress/issues" },
+ "version": "0.0.2",
+ "author": "wave.to",
+ "contributors": [
+ { "name": "Woody Anderson", "email": "woody.anderson@gmail.com"}
+ ],
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/wave-to/node-compress.git"
+ },
+ "engine": [ "node >=0.4.0" ],
+ "main": "build/default/compress",
+ "directories.lib": "build/default/",
+ "scripts": {
+ "build" : "node-waf configure build",
+ "test" : "node-waf test",
+ "doc" : "node-waf doc"
+ }
+}
View
20 wscript
@@ -1,10 +1,12 @@
import Options
+import platform
from os import unlink, symlink, popen
from os.path import exists
srcdir = "."
blddir = "build"
-VERSION = "0.0.1"
+VERSION = "0.0.2"
+OSTYPE = platform.system()
def set_options(opt):
opt.tool_options("compiler_cxx")
@@ -15,10 +17,24 @@ def configure(conf):
conf.check_tool("compiler_cc")
conf.check_tool("node_addon")
- conf.check(lib='z', libpath=['/usr/lib', '/usr/local/lib'], uselib_store='ZLIB')
+ conf.check(lib='z', libpath=['/usr/lib', '/usr/local/lib', '/opt/local/lib'], uselib_store='ZLIB')
def build(bld):
obj = bld.new_task_gen("cxx", "shlib", "node_addon")
+ obj.cxxflags = ['-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE', '-Wall', '-O2']
+ obj.libpath = ['/usr/lib', '/usr/local/lib']
+ obj.includes = ['/usr/include', '/usr/local/include']
+ obj.ldflags = []
+
+ if OSTYPE == 'Darwin':
+ obj.cxxflags.append('-mmacosx-version-min=10.4')
+ obj.ldflags.append('-mmacosx-version-min=10.4')
+ obj.libpath.append('/opt/local/lib')
+ obj.includes.append('/opt/local/include')
+ else:
+ # default build flags, add special cases if needed
+ pass
+
obj.target = "compress"
obj.source = "compress.cc"
obj.uselib = "ZLIB"

0 comments on commit c6f9096

Please sign in to comment.