Permalink
Browse files

first stab at node v0.6.0 support, and moving tests to expresso

  • Loading branch information...
1 parent e1fc4d1 commit 40b05de4cf6fc4bb63df264c3ce471915adbb19f Dane Springmeyer committed Nov 8, 2011
View
@@ -4,4 +4,5 @@ build
*.o
*.a
lib/_zipfile.node
-deps/libzip-*/
+deps/libzip-*/
+node_modules
View
@@ -13,4 +13,12 @@ uninstall:
node-waf -v uninstall
test:
- node test.js
+ @NODE_PATH=.:./lib:$NODE_PATH ./node_modules/.bin/expresso
+
+fix:
+ @fixjsstyle lib/*js bin/*js test/*js
+
+lint:
+ @./node_modules/.bin/jshint lib/*js bin/*js test/*js
+
+.PHONY: test lint fix
View
@@ -25,61 +25,61 @@
## Installation
- You can install the latest tag via npm:
-
- $ npm install zipfile
-
- Or install from github master:
-
- $ git clone git://github.com/springmeyer/node-zipfile.git
- $ cd node-zipfile
- $ ./configure
- $ make
- $ make install
+You can install the latest tag via npm:
+
+ npm install zipfile
+
+Or install from github master:
+
+ git clone git://github.com/springmeyer/node-zipfile.git
+ cd node-zipfile
+ ./configure
+ make
+ make install
## Dynamically linking against libzip
- node-zipfile depends on libzip, but by default
- bundles a copy in deps/ which is statically linked.
-
- If you want to use an external libzip first install it:
-
- Debian:
-
- $ sudo apt-get install libzip-dev libzip1
-
- OS X:
-
- $ brew install libzip
-
- Or from source:
-
- $ wget http://nih.at/libzip/libzip-0.10.tar.bz2
- $ tar xvf libzip-0.10.tar.bz2
- $ cd libzip-0.10
- $ ./configure
- $ make
- $ sudo make install
-
- Then on linux do:
+node-zipfile depends on libzip, but by default
+bundles a copy in deps/ which is statically linked.
+
+If you want to use an external libzip first install it:
+
+Debian:
+
+ sudo apt-get install libzip-dev libzip1
+
+OS X:
- $ sudo ldconfig
+ brew install libzip
+
+Or from source:
+
+ wget http://nih.at/libzip/libzip-0.10.tar.bz2
+ tar xvf libzip-0.10.tar.bz2
+ cd libzip-0.10
+ ./configure
+ make
+ sudo make install
+
+Then on linux do:
+
+ sudo ldconfig
+
+Now, configure node-zipfile with the --shared-libzip option:
+
+ ./configure --shared-libzip
- Now, configure node-zipfile with the --shared-libzip option:
-
- $ ./configure --shared-libzip
+If you installed libzip in a custom location then configure like:
- If you installed libzip in a custom location then configure like:
-
- $ ./configure --shared-libzip --libzip=/opt/local
+ ./configure --shared-libzip --libzip=/opt/local
- Otherwise /usr/ and /usr/local will be searched for libzip:
+Otherwise /usr/ and /usr/local will be searched for libzip:
- $ ./configure --shared-libzip
- $ make
- $ sudo make install
- $ ./test.js
+ ./configure --shared-libzip
+ make
+ sudo make install
+ ./test.js
## License
View
@@ -3,11 +3,7 @@
var zip = require('zipfile');
var fs = require('fs');
var path = require('path');
-
-// node compatibility for mkdirs below
-var constants = (!process.EEXIST >= 1) ?
- require('constants') :
- { EEXIST: process.EEXIST };
+var constants = require('constants');
var usage = 'usage: unzip.js <zipfile>';
@@ -22,7 +18,7 @@ var zf = new zip.ZipFile(file);
zf.names.forEach(function(name) {
var uncompressed = path.join('.', name);
var dirname = path.dirname(uncompressed);
- fs.mkdir(dirname, 0755 , function(err) {
+ fs.mkdir(dirname, '0755' , function(err) {
if (err && err.errno != constants.EEXIST) throw err;
if (path.extname(name)) {
var buffer = zf.readFileSync(name);
View
@@ -1 +1 @@
-module.exports = require('./zipfile');
+module.exports = require('./zipfile');
View
@@ -15,14 +15,18 @@
"contributors" : [],
"licenses" : ["BSD"],
"dependencies" : [],
+ "devDependencies": {
+ "expresso": "~0.9.x",
+ "jshint" : "~0.5.x"
+ },
"bin" : {
"unzip.js" : "./bin/unzip.js"
},
"directories" : {
"examples" : "examples",
"src": "src"
},
- "engines" : { "node": ">=0.2.4 <0.5" },
+ "engines" : { "node": ">=0.6.0 <0.7" },
"scripts" : {
"install" : "node-waf configure build",
"test" : "make test"
View
@@ -5,10 +5,8 @@
#include <vector>
#include <cstring>
#include <algorithm>
-//#include <iostream>
#include <node_buffer.h>
-#include <node_version.h>
#define TOSTR(obj) (*String::Utf8Value((obj)->ToString()))
@@ -34,11 +32,11 @@ void ZipFile::Initialize(Handle<Object> target) {
target->Set(String::NewSymbol("ZipFile"),constructor->GetFunction());
}
-ZipFile::ZipFile(std::string const& file_name) :
- ObjectWrap(),
- file_name_(file_name),
- archive_(),
- names_() {}
+ZipFile::ZipFile(std::string const& file_name)
+ : ObjectWrap(),
+ file_name_(file_name),
+ archive_(),
+ names_() {}
ZipFile::~ZipFile() {
zip_close(archive_);
@@ -158,18 +156,13 @@ Handle<Value> ZipFile::readFileSync(const Arguments& args)
return ThrowException(Exception::Error(String::New(s.str().c_str())));
}
- #if NODE_VERSION_AT_LEAST(0,3,0)
- node::Buffer *retbuf = Buffer::New((char *)&data[0],data.size());
- #else
- node::Buffer *retbuf = Buffer::New(data.size());
- std::memcpy(retbuf->data(), (char *)&data[0], data.size());
- #endif
-
+ node::Buffer *retbuf = Buffer::New((char *)&data[0],data.size());
zip_fclose(zf_ptr);
return scope.Close(retbuf->handle_);
}
typedef struct {
+ uv_work_t request;
ZipFile* zf;
struct zip *za;
std::string name;
@@ -203,6 +196,7 @@ Handle<Value> ZipFile::readFile(const Arguments& args)
ZipFile* zf = ObjectWrap::Unwrap<ZipFile>(args.This());
closure_t *closure = new closure_t();
+ closure->request.data = closure;
// libzip is not threadsafe so we cannot use the zf->archive_
// instead we open a new zip archive for each thread
@@ -223,14 +217,13 @@ Handle<Value> ZipFile::readFile(const Arguments& args)
closure->error = false;
closure->name = name;
closure->cb = Persistent<Function>::New(Handle<Function>::Cast(args[args.Length()-1]));
- eio_custom(EIO_ReadFile, EIO_PRI_DEFAULT, EIO_AfterReadFile, closure);
- ev_ref(EV_DEFAULT_UC);
+ uv_queue_work(uv_default_loop(), &closure->request, EIO_ReadFile, EIO_AfterReadFile);
zf->Ref();
return Undefined();
}
-int ZipFile::EIO_ReadFile(eio_req *req)
+void ZipFile::EIO_ReadFile(uv_work_t* req)
{
closure_t *closure = static_cast<closure_t *>(req->data);
@@ -281,10 +274,9 @@ int ZipFile::EIO_ReadFile(eio_req *req)
}
zip_fclose(zf_ptr);
- return 0;
}
-int ZipFile::EIO_AfterReadFile(eio_req *req)
+void ZipFile::EIO_AfterReadFile(uv_work_t* req)
{
HandleScope scope;
@@ -315,6 +307,5 @@ int ZipFile::EIO_AfterReadFile(eio_req *req)
closure->zf->Unref();
closure->cb.Dispose();
delete closure;
- return 0;
}
@@ -4,6 +4,7 @@
#include <v8.h>
#include <node.h>
#include <node_object_wrap.h>
+#include <node_version.h>
// stl
#include <string>
@@ -32,8 +33,8 @@ class ZipFile: public node::ObjectWrap {
// Async
static Handle<Value> readFile(const Arguments& args);
- static int EIO_ReadFile(eio_req *req);
- static int EIO_AfterReadFile(eio_req *req);
+ static void EIO_ReadFile(uv_work_t* req);
+ static void EIO_AfterReadFile(uv_work_t* req);
ZipFile(std::string const& file_name);
View
@@ -2,53 +2,15 @@
var zipfile = require('./lib/zipfile');
var assert = require('assert');
-var path = require('path');
-var fs = require('fs');
// node compatibility for mkdirs below
var constants = (!process.EEXIST >= 1) ?
require('constants') :
{ EEXIST: process.EEXIST };
-// created with:
-// $ zip -9vr test.zip *txt -c "a comment" -z "zipfile comment"
-var zf = new zipfile.ZipFile('./data/test.zip');
-//console.log(zf)
-assert.equal(zf.count, 2);
-assert.deepEqual(zf.names, ['one.txt', 'two.txt']);
-
-// created with /System/Library/CoreServices/Archive Utility.app
-var zf = new zipfile.ZipFile('./data/Archive.zip');
-//console.log(zf)
-assert.equal(zf.count, 2);
-assert.deepEqual(zf.names, ['one.txt', 'two.txt']);
-
-var zf = new zipfile.ZipFile('./data/folder.zip');
-assert.equal(zf.count, 3); // one folder, two files
-assert.deepEqual(zf.names, ['folder/', 'folder/one.txt', 'folder/two.txt']);
-
-assert.throws(function() { zf.readFileSync('foo')});
var zf = new zipfile.ZipFile('./data/world_merc.zip');
-
-function mkdirP(p, mode, f) {
- var cb = f || function() {};
- // if relative
- if (p.charAt(0) != '/') {
- // if >= node 0.3.0 use path.resolve()
- p = path.join(__dirname, p);
- }
- var ps = path.normalize(p).split('/');
- path.exists(p, function(exists) {
- if (exists) cb(null);
- else mkdirP(ps.slice(0, -1).join('/'), mode, function(err) {
- if (err && err.errno != contants.EEXIST) cb(err);
- else fs.mkdir(p, mode, cb);
- });
- });
-}
-
// test writing with Sync reading method
// and sync node writing functions
zf.names.forEach(function(name) {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -13,7 +13,7 @@ import Utils
TARGET = '_zipfile'
TARGET_FILE = '%s.node' % TARGET
-built = 'build/default/%s' % TARGET_FILE
+built = 'build/Release/%s' % TARGET_FILE
dest = 'lib/%s' % TARGET_FILE
settings = 'lib/settings.js'
BUNDLED_LIBZIP_VERSION = '0.10'

0 comments on commit 40b05de

Please sign in to comment.