node-zipfile-0.4.0/0000755000175000017500000000000012201301614012204 5ustar devdevnode-zipfile-0.4.0/test/0000755000175000017500000000000012201301614013163 5ustar devdevnode-zipfile-0.4.0/test/data/0000755000175000017500000000000012210115157014101 5ustar devdevnode-zipfile-0.4.0/test/data/你好_points.csv0000644000175000017500000000006212201301614020472 0ustar devdevx,y,bigint 0,0,2147483648 0,0,9223372036854775807 node-zipfile-0.4.0/test/data/test.zip0000644000175000017500000000052412201301614015600 0ustar devdevPK l3>xone.txtUT 0/7M/7Mux hola PK l3>" two.txtUT H/7M/7Mux mundo PK l3>xone.txtUT0/7Mux helloPK l3>" Ftwo.txtUTH/7Mux worldPK zippy oh yeahnode-zipfile-0.4.0/test/data/one.txt0000644000175000017500000000000512201301614015411 0ustar devdevhola node-zipfile-0.4.0/test/data/ééé/0000755000175000017500000000000012201301614016257 5ustar devdevnode-zipfile-0.4.0/test/data/ééé/foo.csv.zip0000644000175000017500000000103012201301614020352 0ustar devdevPKt0Bfoo.csvUX QPQPЩ21PK7Xy PK x0B __MACOSX/UX QPQPPKt0B__MACOSX/._foo.csvUX QPQPc`cg`b`MLVVP'q%!!AP&H GSˆOK,(I I(qKOKJZX[ZPKp]PKt0B7Xy  @foo.csvUXQPQPPK x0B @AN__MACOSX/UXQPQPPKt0Bp] @__MACOSX/._foo.csvUXQPQPPK2node-zipfile-0.4.0/test/data/ééé/foo.csv0000644000175000017500000000000712201301614017554 0ustar devdevx,y 0,0node-zipfile-0.4.0/test/data/Clément/0000755000175000017500000000000012201301614016072 5ustar devdevnode-zipfile-0.4.0/test/data/Clément/foo.csv.zip0000644000175000017500000000103012201301614020165 0ustar devdevPKt0Bfoo.csvUX QPQPЩ21PK7Xy PK x0B __MACOSX/UX QPQPPKt0B__MACOSX/._foo.csvUX QPQPc`cg`b`MLVVP'q%!!AP&H GSˆOK,(I I(qKOKJZX[ZPKp]PKt0B7Xy  @foo.csvUXQPQPPK x0B @AN__MACOSX/UXQPQPPKt0Bp] @__MACOSX/._foo.csvUXQPQPPK2node-zipfile-0.4.0/test/data/Clément/Olá.zip0000644000175000017500000000024712201301614017737 0ustar devdevPKR@ Olá.txtUX +P+P9 PKone.txtUX W/7M0/7MIPKxPKl3>two.txtUX W/7MH/7M-KPK" PKl3>x @one.txtUXW/7M0/7MPKl3>"  @Ltwo.txtUXW/7MH/7MPKnode-zipfile-0.4.0/test/data/invalid.zip0000644000175000017500000000003212201301614016241 0ustar devdevthis is not a zip archive node-zipfile-0.4.0/test/data/two.txt0000644000175000017500000000000612201301614015442 0ustar devdevmundo node-zipfile-0.4.0/test/data/points.csv.zip0000644000175000017500000000114712201301614016731 0ustar devdevPK a0B你好_points.csvUX PPЩIL+2112417063s-͍ ,LMM- ̹PK N02PK na0B __MACOSX/UX o Po PPK a0B__MACOSX/._你好_points.csvUX PPc`cg`b`MLVVP'q%!!AP&H GSˆOK,(I I(qKOKJZX[ZPKp]PK a0B N02 @你好_points.csvUXPPPK na0B @A__MACOSX/UXo Po PPK a0Bp] @__MACOSX/._你好_points.csvUXPPPKmnode-zipfile-0.4.0/test/data/folder.zip0000644000175000017500000000070312201301614016073 0ustar devdevPK U3>folder/UX xP7MP7MPKl3>folder/one.txtUX P7M0/7MIPKxPKl3>folder/two.txtUX P7MH/7M-KPK" PK U3> @Afolder/UXxP7MP7MPKl3>x @5folder/one.txtUXP7M0/7MPKl3>"  @folder/two.txtUXP7MH/7MPKnode-zipfile-0.4.0/test/unicode.test.js0000644000175000017500000000372512201301614016134 0ustar devdevvar zipfile = require('zipfile'); var assert = require('assert'); var fs = require('fs'); var existsSync = require('fs').existsSync || require('path').existsSync; describe('Handling unicode paths, filenames, and data', function(){ it('open zip with folder with unicode', function(){ var zippath = './test/data/Clément/foo.csv.zip'; assert.ok(existsSync(zippath)); var zf = new zipfile.ZipFile(zippath); assert.equal(zf.count, 3); var buffer = zf.readFileSync(zf.names[0]); assert.equal(buffer.toString('utf8'),fs.readFileSync(zippath.replace('.zip','')).toString('utf8').replace(/\r/g,'')); }); it('open zip with folder and file with unicode', function(){ var zippath = './test/data/Clément/Olá.zip'; assert.ok(existsSync(zippath)); var zf = new zipfile.ZipFile(zippath); assert.equal(zf.count, 1); }); it('open zip with unicode paths and unicode filenames in archive', function(){ var zippath = './test/data/Clément/Olá.zip'; assert.ok(existsSync(zippath)); var zf = new zipfile.ZipFile(zippath); assert.equal(zf.count, 1); assert.deepEqual(zf.names, ['Olá.txt']); zf.names.forEach(function(name) { var buffer = zf.readFileSync(name); assert.equal(buffer.toString('utf8'),'Olá\n'); }); }); it('open zip with ansi path but unicode filename in archive', function(){ // created with OS X 10.7 with right-click, then "compress" var zippath = './test/data/points.csv.zip'; assert.ok(existsSync(zippath)); var zf = new zipfile.ZipFile(zippath); assert.equal(zf.count, 3); assert.deepEqual(zf.names, ["你好_points.csv","__MACOSX/","__MACOSX/._你好_points.csv"]); var buffer = zf.readFileSync(zf.names[0]); assert.equal(buffer.toString('utf8'),fs.readFileSync('./test/data/你好_points.csv').toString('utf8').replace(/\r/g,'')); }); }); node-zipfile-0.4.0/test/open.test.js0000644000175000017500000000173712201301614015450 0ustar devdevvar zipfile = require('zipfile'); var assert = require('assert'); describe('Opening', function(){ it('folder based archive should open', function(){ var zf = new zipfile.ZipFile('./test/data/folder.zip'); assert.equal(zf.count, 3); // one folder, two files assert.deepEqual(zf.names, ['folder/', 'folder/one.txt', 'folder/two.txt']); }); it('opening unix zip created archive', function(){ // created with: // $ zip -9vr test.zip *txt -c "a comment" -z "zipfile comment" var zf = new zipfile.ZipFile('./test/data/test.zip'); assert.equal(zf.count, 2); assert.deepEqual(zf.names, ['one.txt', 'two.txt']); }); it('test opening mac created archive', function(){ // created with /System/Library/CoreServices/Archive Utility.app var zf = new zipfile.ZipFile('./test/data/Archive.zip'); assert.equal(zf.count, 2); assert.deepEqual(zf.names, ['one.txt', 'two.txt']); }); }); node-zipfile-0.4.0/test/write.test.js0000644000175000017500000000441412201301614015634 0ustar devdevvar zipfile = require('zipfile'); var assert = require('assert'); var path = require('path'); var fs = require('fs'); var constants = require('constants'); var mkdirp = require('mkdirp'); var existsSync = require('fs').existsSync || require('path').existsSync; describe('Async Writes', function(){ var zf = new zipfile.ZipFile('./test/data/world_merc.zip'); zf.names.forEach(function(name) { it('async write '+ name, function(done){ var dest = path.join(__dirname,'tmp', name); mkdirp(path.dirname(dest), 0755 , function(err) { if (err) throw err; if (path.extname(name)) { zf.readFile(name, function(err, buffer) { if (err) throw err; fs.open(dest, 'w', 0644, function(err, fd) { if (err) throw err; fs.write(fd, buffer, 0, buffer.length, null, function(err,written) { if (err) throw err; // written is number of bytes written assert.ok(written > 0); fs.close(fd, function(err) { if (err) throw err; done(); }); }); }); }); } }); }); }); }); describe('Sync Writes', function(){ var zf = new zipfile.ZipFile('./test/data/world_merc.zip'); zf.names.forEach(function(name) { var uncompressed = path.join('/tmp/sync', name); var dirname = path.dirname(uncompressed); mkdirp(dirname, 0755 , function(err) { it('sync write '+ name, function(done){ if (err && !err.message.match(/^EEXIST/)) throw err; if (path.extname(name)) { var buffer = zf.readFileSync(name); var fd = fs.openSync(uncompressed, 'w'); fs.writeSync(fd, buffer, 0, buffer.length, null); fs.closeSync(fd); assert.ok(existsSync(uncompressed)); done(); } }); }); }); });node-zipfile-0.4.0/test/exceptions.test.js0000644000175000017500000000115112201301614016656 0ustar devdevvar zipfile = require('zipfile'); var assert = require('assert'); describe('Exceptions', function(){ it('should throw as archive does not exit', function(){ assert.throws(function() { new zipfile.ZipFile('thisdoesnotexist.zip'); }); }); it('should throw as the file is invalid', function(){ assert.throws(function() { new zipfile.ZipFile('./test/data/invalid.zip'); }); }); it('should throw as the file in the archive does not exit', function(){ var zf = new zipfile.ZipFile('./test/data/folder.zip'); assert.throws(function() { zf.readFileSync('foo'); }); }); });node-zipfile-0.4.0/lib/0000755000175000017500000000000012201301614012752 5ustar devdevnode-zipfile-0.4.0/lib/zipfile.js0000644000175000017500000000012412201301614014747 0ustar devdevvar zipfile = require('./node_zipfile.node'); exports = module.exports = zipfile; node-zipfile-0.4.0/lib/index.js0000644000175000017500000000004712201301614014420 0ustar devdevmodule.exports = require('./zipfile'); node-zipfile-0.4.0/README.md0000644000175000017500000000457012201301614013471 0ustar devdev# node-zipfile Bindings to [libzip](http://nih.at/libzip/libzip.html) for handling zipfile archives in [node](http://nodejs.org). ## Example var zipfile = require('zipfile'); var zf = new zipfile.ZipFile('./test/data/world_merc.zip'); zf { names: [ 'world_merc.dbf', 'world_merc.prj', 'world_merc.shp', 'world_merc.shx' ], count: 4 } var buffer = zf.readFileSync('world_merc.prj'); buffer.toString() 'PROJCS["Google Maps Global Mercator",GEOGCS .... ' ## Depends node-zipfile 0.3.x depends on node v0.6 and above node-zipfile 0.1.x-0.2.x works with node v0.2-v0.4 libzip (optionally, otherwise will build against bundled version) ## 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 ## 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: sudo ldconfig Now, configure node-zipfile with the --shared-libzip option: ./configure --shared-libzip If you installed libzip in a custom location then configure like: ./configure --shared-libzip --libzip=/opt/local Otherwise /usr/ and /usr/local will be searched for libzip: ./configure --shared-libzip make sudo make install ./test.js ## Building libzip with cmake on windows: Note: needs cygwin so the .sh shell scripts work that libzip cmake files call. git clone git://github.com/springmeyer/node-zipfile.git cd node-zipfile/deps/ bsdtar xvf libzip-0.10.tar.bz2 cd libzip mkdir build_vc100 cd build_vc100 cmake -DZLIB_LIBRARY=c:\dev2\zlib\zlib.lib -DZLIB_INCLUDE_DIR=c:\dev2\zlib -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release ..\ Then edit lib\zipconf.h removing 'inttypes.h' with: #include #include Finally build libzip nmake /f Makefile zip Then compile node-zipfile: TODO ## License BSD, see LICENSE.txtnode-zipfile-0.4.0/configure0000755000175000017500000000011512201301614014110 0ustar devdev#!/bin/sh `npm explore npm -g -- pwd`/bin/node-gyp-bin/node-gyp configure $@node-zipfile-0.4.0/LICENSE.txt0000644000175000017500000000311212201301614014024 0ustar devdevCopyright (c) 2011, Dane Springmeyer All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This project also includes code and files from GDAL, see GDAL_LICENSE for more details.node-zipfile-0.4.0/bin/0000755000175000017500000000000012201301614012754 5ustar devdevnode-zipfile-0.4.0/bin/unzip.js0000755000175000017500000000142212201301614014461 0ustar devdev#!/usr/bin/env node var zip = require('zipfile'); var fs = require('fs'); var path = require('path'); var usage = 'usage: unzip.js '; var file = process.argv[2]; if (!file) { console.log(usage); process.exit(1); } 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) { if (err && !err.code.match(/^EEXIST/)) throw err; if (path.extname(name)) { var buffer = zf.readFileSync(name); fd = fs.openSync(uncompressed, 'w'); console.log('unzipping: ' + name); fs.writeSync(fd, buffer, 0, buffer.length, null); fs.closeSync(fd); } }); }); node-zipfile-0.4.0/test.js0000755000175000017500000000354612201301614013534 0ustar devdev#!/usr/bin/env node var zipfile = require('./lib/zipfile'); var assert = require('assert'); // node compatibility for mkdirs below var constants = (!process.EEXIST >= 1) ? require('constants') : { EEXIST: process.EEXIST }; var zf = new zipfile.ZipFile('./data/world_merc.zip'); // test writing with Sync reading method // and sync node writing functions zf.names.forEach(function(name) { var uncompressed = path.join('/tmp/sync', name); var dirname = path.dirname(uncompressed); mkdirP(dirname, 0755 , function(err) { if (err && err.errno != constants.EEXIST) throw err; if (path.extname(name)) { var buffer = zf.readFileSync(name); fd = fs.openSync(uncompressed, 'w'); fs.writeSync(fd, buffer, 0, buffer.length, null); fs.closeSync(fd); } }); }); // test writing with Async reading method // and async node writing functions zf.names.forEach(function(name) { var uncompressed = path.join('/tmp/async', name); var dirname = path.dirname(uncompressed); mkdirP(dirname, 0755 , function(err) { if (err && err.errno != constants.EEXIST) throw err; if (path.extname(name)) { zf.readFile(name, function(err, buffer) { if (err) throw err; fs.open(uncompressed, 'w', 0755, function(err,fd) { if (err) throw err; fs.write(fd, buffer, 0, buffer.length, null, function(err,written) { if (err) throw err; // written is number of bytes written assert.ok(written > 0); fs.close(fd, function(err) { if (err) throw err; }); }); }); }); } }); }); console.log('All tests pass...'); node-zipfile-0.4.0/src/0000755000175000017500000000000012201301614012773 5ustar devdevnode-zipfile-0.4.0/src/node_zipfile.cpp0000644000175000017500000003050312201301614016147 0ustar devdev#include "node_zipfile.hpp" #include #include #ifdef _WINDOWS #include #endif // std #include #include #include #include #include #define TOSTR(obj) (*String::Utf8Value((obj)->ToString())) #ifdef _WINDOWS std::string wstring2string(const std::wstring& s) { DWORD size = WideCharToMultiByte(CP_UTF8, 0, s.c_str(), -1, NULL, 0, NULL, NULL); if (size == 0) { // This should never happen. fprintf(stderr, "Could not convert arguments to utf8."); } char * buf_ptr = new char [size]; DWORD result = WideCharToMultiByte(CP_ACP, 0, s.c_str(), -1, buf_ptr, size, NULL, NULL); if (result == 0) { // This should never happen. fprintf(stderr, "Could not convert arguments to utf8."); } std::string r(buf_ptr); delete buf_ptr; return r; } std::wstring utf8ToWide( std::string const& s ) { int ws_len, r; WCHAR* ws; ws_len = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, NULL, 0); ws = new wchar_t [ws_len * sizeof(WCHAR)]; if (ws == NULL) { // This should never happen. fprintf(stderr, "Could not convert arguments from utf8."); exit(1); } r = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, ws, ws_len); if (r != ws_len) { // This should never happen. fprintf(stderr, "Could not do anything useful."); exit(1); } std::wstring rt(ws); delete ws; return rt; } #endif Persistent ZipFile::constructor; void ZipFile::Initialize(Handle target) { HandleScope scope; constructor = Persistent::New(FunctionTemplate::New(ZipFile::New)); constructor->InstanceTemplate()->SetInternalFieldCount(1); constructor->SetClassName(String::NewSymbol("ZipFile")); // functions NODE_SET_PROTOTYPE_METHOD(constructor, "readFileSync", readFileSync); NODE_SET_PROTOTYPE_METHOD(constructor, "readFile", readFile); // properties constructor->InstanceTemplate()->SetAccessor(String::NewSymbol("count"), get_prop); constructor->InstanceTemplate()->SetAccessor(String::NewSymbol("names"), get_prop); target->Set(String::NewSymbol("ZipFile"), constructor->GetFunction()); } ZipFile::ZipFile(std::string const& file_name) : ObjectWrap(), file_name_(file_name), names_() {} Handle ZipFile::New(const Arguments& args) { HandleScope scope; if (!args.IsConstructCall()) return ThrowException(String::New("Cannot call constructor as function, you need to use 'new' keyword")); if (args.Length() != 1 || !args[0]->IsString()) return ThrowException(Exception::TypeError( String::New("first argument must be a path to a zipfile"))); std::string input_file = TOSTR(args[0]); #ifdef _WINDOWS input_file = wstring2string(utf8ToWide(input_file)); #endif int err; char errstr[1024]; struct zip *za; if ((za=zip_open(input_file.c_str(), 0, &err)) == NULL) { zip_error_to_str(errstr, sizeof(errstr), err, errno); std::stringstream s; s << "cannot open file: " << input_file << " error: " << errstr << "\n"; zip_close(za); return ThrowException(Exception::Error( String::New(s.str().c_str()))); } ZipFile* zf = new ZipFile(input_file); int num = zip_get_num_files(za); zf->names_.reserve(num); int i = 0; for (i = 0; i < num; i++) { struct zip_stat st; zip_stat_index(za, i, 0, &st); std::string name = st.name; zf->names_.push_back(name); } zip_close(za); zf->Wrap(args.This()); return args.This(); } Handle ZipFile::get_prop(Local property, const AccessorInfo& info) { HandleScope scope; ZipFile* zf = ObjectWrap::Unwrap(info.This()); std::string a = TOSTR(property); if (a == "count") { return scope.Close(Integer::New(zf->names_.size())); } if (a == "names") { unsigned num = zf->names_.size(); Local a = Array::New(num); for (unsigned i = 0; i < num; ++i) { a->Set(i, String::New(zf->names_[i].c_str())); } return scope.Close(a); } return Undefined(); } Handle ZipFile::readFileSync(const Arguments& args) { HandleScope scope; if (args.Length() != 1 || !args[0]->IsString()) return ThrowException(Exception::TypeError( String::New("first argument must be a file name inside the zip"))); std::string name = TOSTR(args[0]); ZipFile* zf = ObjectWrap::Unwrap(args.This()); int idx = -1; std::vector::iterator it = std::find(zf->names_.begin(), zf->names_.end(), name); if (it != zf->names_.end()) { idx = distance(zf->names_.begin(), it); } if (idx == -1) { std::stringstream s; s << "No file found by the name of: '" << name << "\n"; return ThrowException(Exception::Error(String::New(s.str().c_str()))); } int err; char errstr[1024]; struct zip *za; if ((za=zip_open(zf->file_name_.c_str(), 0, &err)) == NULL) { zip_error_to_str(errstr, sizeof(errstr), err, errno); std::stringstream s; s << "cannot open file: " << zf->file_name_ << " error: " << errstr << "\n"; zip_close(za); return ThrowException(Exception::Error( String::New(s.str().c_str()))); } struct zip_file *zf_ptr; if ((zf_ptr=zip_fopen_index(za, idx, 0)) == NULL) { if (zf_ptr) zip_fclose(zf_ptr); std::stringstream s; s << "cannot open file #" << idx << " in " << name << ": archive error: " << zip_strerror(za) << "\n"; zip_close(za); return ThrowException(Exception::Error(String::New(s.str().c_str()))); } struct zip_stat st; zip_stat_index(za, idx, 0, &st); std::vector data; data.clear(); data.resize(st.size); int result = 0; result = static_cast(zip_fread(zf_ptr, reinterpret_cast (&data[0]), data.size())); if (result < 0) { std::stringstream s; s << "error reading file #" << idx << " in " << name << ": archive error: " << zip_file_strerror(zf_ptr) << "\n"; zip_fclose(zf_ptr); zip_close(za); return ThrowException(Exception::Error(String::New(s.str().c_str()))); } node::Buffer *retbuf = Buffer::New(reinterpret_cast(&data[0]), data.size()); zip_fclose(zf_ptr); zip_close(za); return scope.Close(retbuf->handle_); } typedef struct { uv_work_t request; ZipFile* zf; struct zip *za; std::string name; bool error; std::string error_name; std::vector data; Persistent cb; } closure_t; Handle ZipFile::readFile(const Arguments& args) { HandleScope scope; if (args.Length() < 2) return ThrowException(Exception::TypeError( String::New("requires two arguments, the name of a file and a callback"))); // first arg must be name if (!args[0]->IsString()) return ThrowException(Exception::TypeError( String::New("first argument must be a file name inside the zip"))); // last arg must be function callback if (!args[args.Length()-1]->IsFunction()) return ThrowException(Exception::TypeError( String::New("last argument must be a callback function"))); std::string name = TOSTR(args[0]); ZipFile* zf = ObjectWrap::Unwrap(args.This()); closure_t *closure = new closure_t(); closure->request.data = closure; // libzip is not threadsafe so we open a new zip archive for each thread int err; char errstr[1024]; if ((closure->za=zip_open(zf->file_name_.c_str() , 0, &err)) == NULL) { zip_error_to_str(errstr, sizeof(errstr), err, errno); std::stringstream s; s << "cannot open file: " << zf->file_name_ << " error: " << errstr << "\n"; zip_close(closure->za); closure->cb.Dispose(); delete closure; return ThrowException(Exception::Error( String::New(s.str().c_str()))); } closure->zf = zf; closure->error = false; closure->name = name; closure->cb = Persistent::New(Handle::Cast(args[args.Length()-1])); uv_queue_work(uv_default_loop(), &closure->request, Work_ReadFile, (uv_after_work_cb)Work_AfterReadFile); zf->Ref(); return Undefined(); } void ZipFile::Work_ReadFile(uv_work_t* req) { closure_t *closure = static_cast(req->data); struct zip_file *zf_ptr = NULL; int idx = -1; std::vector::iterator it = std::find(closure->zf->names_.begin(), closure->zf->names_.end(), closure->name); if (it != closure->zf->names_.end()) { idx = distance(closure->zf->names_.begin(), it); } if (idx == -1) { std::stringstream s; s << "No file found by the name of: '" << closure->name << "\n"; closure->error = true; closure->error_name = s.str(); } else { if ((zf_ptr = zip_fopen_index(closure->za, idx, 0)) == NULL) { std::stringstream s; s << "cannot open file #" << idx << " in " << closure->name << ": archive error: " << zip_strerror(closure->za) << "\n"; closure->error = true; closure->error_name = s.str(); } else { struct zip_stat st; zip_stat_index(closure->za, idx, 0, &st); closure->data.clear(); closure->data.resize(st.size); int result = 0; result = static_cast(zip_fread(zf_ptr, reinterpret_cast (&closure->data[0]), closure->data.size())); if (result < 0) { std::stringstream s; s << "error reading file #" << idx << " in " << closure->name << ": archive error: " << zip_file_strerror(zf_ptr) << "\n"; closure->error = true; closure->error_name = s.str(); } } } zip_fclose(zf_ptr); } void ZipFile::Work_AfterReadFile(uv_work_t* req) { HandleScope scope; closure_t *closure = static_cast(req->data); TryCatch try_catch; if (closure->error) { Local argv[1] = { Exception::Error(String::New(closure->error_name.c_str())) }; closure->cb->Call(Context::GetCurrent()->Global(), 1, argv); } else { node::Buffer *retbuf = Buffer::New(reinterpret_cast(&closure->data[0]), closure->data.size()); Local argv[2] = { Local::New(Null()), Local::New(retbuf->handle_) }; closure->cb->Call(Context::GetCurrent()->Global(), 2, argv); } if (try_catch.HasCaught()) { FatalException(try_catch); } zip_close(closure->za); closure->zf->Unref(); closure->cb.Dispose(); delete closure; } extern "C" { static void init(Handle target) { ZipFile::Initialize(target); // node-zipfile version target->Set(String::NewSymbol("version"), String::New("0.3.1")); // versions of deps Local versions = Object::New(); versions->Set(String::NewSymbol("node"), String::New(NODE_VERSION+1)); versions->Set(String::NewSymbol("v8"), String::New(V8::GetVersion())); target->Set(String::NewSymbol("versions"), versions); } NODE_MODULE(node_zipfile, init); } node-zipfile-0.4.0/src/node_zipfile.hpp0000644000175000017500000000204712201301614016156 0ustar devdev#ifndef INCLUDE_ZIPFILE_NODE_ZIPFILE_H_ #define INCLUDE_ZIPFILE_NODE_ZIPFILE_H_ // libzip extern "C" { #include #include #include } #include #include #include // stl #include #include using namespace v8; using namespace node; class ZipFile: public node::ObjectWrap { public: static Persistent constructor; static void Initialize(Handle target); static Handle New(const Arguments &args); static Handle get_prop(Local property, const AccessorInfo& info); // Sync static Handle readFileSync(const Arguments& args); // Async static Handle readFile(const Arguments& args); static void Work_ReadFile(uv_work_t* req); static void Work_AfterReadFile(uv_work_t* req); explicit ZipFile(std::string const& file_name); private: std::string file_name_; std::vector names_; }; #endif // INCLUDE_ZIPFILE_NODE_ZIPFILE_H_ node-zipfile-0.4.0/binding.gyp0000644000175000017500000000271712201301614014346 0ustar devdev{ 'includes': [ 'deps/common-libzip.gypi' ], 'variables': { 'libzip%':'internal', }, 'conditions': [ ['OS=="win"', { 'variables': { 'copy_command%': 'copy', }, },{ 'variables': { 'copy_command%': 'cp', }, }] ], 'targets': [ { 'target_name': 'node_zipfile', 'conditions': [ ['libzip != "internal"', { 'libraries': [ '-L<@(libzip)/lib', '-lzip' ], 'include_dirs': [ '<@(libzip)/include' ] }, { 'dependencies': [ 'deps/libzip.gyp:libzip' ] } ] ], 'sources': [ 'src/node_zipfile.cpp' ], }, { 'target_name': 'action_after_build', 'type': 'none', 'dependencies': [ 'node_zipfile' ], 'actions': [ { 'action_name': 'move_node_module', 'inputs': [ '<@(PRODUCT_DIR)/node_zipfile.node' ], 'outputs': [ 'lib/node_zipfile.node' ], 'action': ['<(copy_command)', '<@(PRODUCT_DIR)/node_zipfile.node', 'lib/node_zipfile.node'] } ], 'conditions': [ ['OS=="win"', { 'copies': [ { 'files': [ '<(PRODUCT_DIR)/libzip.dll' ], 'destination': 'lib/' } ] }] ] } ] } node-zipfile-0.4.0/Makefile0000755000175000017500000000122312201301614013645 0ustar devdevall: node_zipfile.node node_zipfile.node: `npm explore npm -g -- pwd`/bin/node-gyp-bin/node-gyp build clean: @rm -rf ./build rm -f lib/node_zipfile.node rm -f test/tmp/* rm -rf ./deps/libzip-0.10/ rm -rf ./build rm -rf ./out rebuild: @make clean @./configure @make test: @PATH=./node_modules/mocha/bin:${PATH} && NODE_PATH=./lib:$NODE_PATH mocha -R spec fix: @fixjsstyle lib/*js bin/*js test/*js fixc: @tools/fix_cpp_style.sh lint: @./node_modules/.bin/jshint lib/*js bin/*js test/*js lintc: @cpplint.py --verbose=3 --filter=-legal,-build/namespaces,-whitespace/line_length src/*.* include/zipfile/*.* .PHONY: test lint fix lintc fixcnode-zipfile-0.4.0/.gitignore0000644000175000017500000000014412201301614014173 0ustar devdevbuild .lock-wscript .DS_Store *.o *.a deps/libzip-0.10/ lib/node_zipfile.node node_modules test/tmp/node-zipfile-0.4.0/tools/0000755000175000017500000000000012201301614013344 5ustar devdevnode-zipfile-0.4.0/tools/fix_cpp_style.sh0000755000175000017500000000017112201301614016552 0ustar devdevecho `pwd` for file in $(find ./src/ -name '*.*') do emacs -batch $file -l `pwd`/tools/cpp.el -f fixup_format done node-zipfile-0.4.0/tools/cpp.el0000644000175000017500000000044312201301614014451 0ustar devdev(defun fixup () (c-set-style "bsd") (c-set-offset 'innamespace 0) (c-set-offset 'template-args-cont 'c-lineup-template-args) (setq c-basic-offset 4) (indent-region (point-min) (point-max) nil) (untabify (point-min) (point-max)) (delete-trailing-whitespace) (save-buffer) ) node-zipfile-0.4.0/deps/0000755000175000017500000000000012210115157013144 5ustar devdevnode-zipfile-0.4.0/deps/notes.md0000644000175000017500000000017512201301614014614 0ustar devdevmodified libzip-0.11.1-mod.tar.gz - this patch applied: http://hg.nih.at/libzip/rev/6aeb5008ceeb - lib/zipconf.h removednode-zipfile-0.4.0/deps/common-libzip.gypi0000644000175000017500000000007112201301614016606 0ustar devdev{ 'variables': { 'libzip_version%':'0.11.1' } }node-zipfile-0.4.0/package.json0000644000175000017500000000165012201301614014474 0ustar devdev{ "name" : "zipfile", "version" : "0.4.0", "main" : "./lib/index.js", "description" : "C++ library for handling zipfiles in node", "keywords" : ["zipfile", "uncompress", "unzip", "zlib"], "url" : "http://github.com/springmeyer/node-zipfile", "repositories" : [ { "type" : "git", "url" : "git://github.com/springmeyer/node-zipfile.git" } ], "author" : "Dane Springmeyer ", "contributors" : [], "licenses" : ["BSD"], "dependencies" : {}, "devDependencies": { "mocha": "*", "mkdirp": "~0.3.0", "jshint" : "~0.5.x" }, "bin" : { "unzip.js" : "./bin/unzip.js" }, "directories" : { "examples" : "examples", "src": "src" }, "engines" : { "node": ">= 0.6.13 && < 0.11.0" }, "scripts" : { "test" : "mocha -R spec" } } node-zipfile-0.4.0/vcbuild.bat0000644000175000017500000000017512201301614014327 0ustar devdevrd /q /s build del lib\\node_zipfile.node npm install copy build\Release\libzip.dll lib rem test! set NODE_PATH=lib npm test