node-zipfile-0.5.0+dfsg.orig/0000755000000000000000000000000012307716606014465 5ustar rootrootnode-zipfile-0.5.0+dfsg.orig/test/0000755000000000000000000000000012307716606015444 5ustar rootrootnode-zipfile-0.5.0+dfsg.orig/test/data/0000755000000000000000000000000012311361775016353 5ustar rootrootnode-zipfile-0.5.0+dfsg.orig/test/data/bogus.zip0000644000000000000000000000001312307716606020212 0ustar rootrootbogus data node-zipfile-0.5.0+dfsg.orig/test/data/你好_points.csv0000644000000000000000000000006212307716606022753 0ustar rootrootx,y,bigint 0,0,2147483648 0,0,9223372036854775807 node-zipfile-0.5.0+dfsg.orig/test/data/test.zip0000644000000000000000000000052412307716606020061 0ustar rootrootPK 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.5.0+dfsg.orig/test/data/one.txt0000644000000000000000000000000512307716606017672 0ustar rootroothola node-zipfile-0.5.0+dfsg.orig/test/data/ééé/0000755000000000000000000000000012307716606020540 5ustar rootrootnode-zipfile-0.5.0+dfsg.orig/test/data/ééé/foo.csv.zip0000644000000000000000000000103012307716606022633 0ustar rootrootPKt0Bfoo.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.5.0+dfsg.orig/test/data/ééé/foo.csv0000644000000000000000000000000712307716606022035 0ustar rootrootx,y 0,0node-zipfile-0.5.0+dfsg.orig/test/data/Clément/0000755000000000000000000000000012307716606020353 5ustar rootrootnode-zipfile-0.5.0+dfsg.orig/test/data/Clément/foo.csv.zip0000644000000000000000000000103012307716606022446 0ustar rootrootPKt0Bfoo.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.5.0+dfsg.orig/test/data/Clément/Olá.zip0000644000000000000000000000024712307716606022220 0ustar rootrootPKR@ 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.5.0+dfsg.orig/test/data/invalid.zip0000644000000000000000000000003212307716606020522 0ustar rootrootthis is not a zip archive node-zipfile-0.5.0+dfsg.orig/test/data/two.txt0000644000000000000000000000000612307716606017723 0ustar rootrootmundo node-zipfile-0.5.0+dfsg.orig/test/data/points.csv.zip0000644000000000000000000000114712307716606021212 0ustar rootrootPK 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.5.0+dfsg.orig/test/data/folder.zip0000644000000000000000000000070312307716606020354 0ustar rootrootPK 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.5.0+dfsg.orig/test/unicode.test.js0000644000000000000000000000372012307716606020410 0ustar rootrootvar zipfile = require('..'); 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.5.0+dfsg.orig/test/open.test.js0000644000000000000000000000252612307716606017726 0ustar rootrootvar zipfile = require('..'); 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']); }); it('test opening invalid archive', function(){ // created by doing: // echo 'this is not a zip archive' > test/data/invalid.zip assert.throws(function() { new zipfile.ZipFile('./test/data/invalid.zip'); }); // echo 'bogus data' > test/data/bogus.zip assert.throws(function() { new zipfile.ZipFile('./test/data/bogus.zip'); }); }); }); node-zipfile-0.5.0+dfsg.orig/test/write.test.js0000644000000000000000000000440712307716606020117 0ustar rootrootvar zipfile = require('..'); 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.5.0+dfsg.orig/test/exceptions.test.js0000644000000000000000000000114412307716606021141 0ustar rootrootvar zipfile = require('..'); 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.5.0+dfsg.orig/lib/0000755000000000000000000000000012307716606015233 5ustar rootrootnode-zipfile-0.5.0+dfsg.orig/lib/zipfile.js0000644000000000000000000000005012307716606017226 0ustar rootrootmodule.exports = require('./index.js'); node-zipfile-0.5.0+dfsg.orig/lib/index.js0000644000000000000000000000034212307716606016677 0ustar rootrootvar binary = require('node-pre-gyp'); var path = require('path'); var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json'))); var zipfile = require(binding_path); exports = module.exports = zipfile; node-zipfile-0.5.0+dfsg.orig/README.md0000644000000000000000000000263112307716606015746 0ustar rootroot# node-zipfile Bindings to [libzip](http://nih.at/libzip/libzip.html) for handling zipfile archives in [node](http://nodejs.org). [![Build Status](https://secure.travis-ci.org/mapbox/node-zipfile.png)](http://travis-ci.org/mapbox/node-zipfile) ## 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 v0.10.x or v0.8.x ## Installation Install from binary: npm install Install from source: npm install --build-from-source ## Dynamically linking against libzip `node-zipfile` depends on libzip, but by default bundles a copy in deps/ which is statically linked and packaged as a binary. If you want to use an external libzip first install it: Debian: sudo apt-get install libzip-dev libzip1 OS X: brew install libzip Then configure node-zipfile with the --shared_libzip option: npm install --build-from-source --shared_libzip If you installed libzip in a custom location then configure like: npm install --build-from-source --shared_libzip --shared_libzip_includes=/opt/local/include --shared_libzip_libpath=/opt/local/lib ## License BSD, see LICENSE.txtnode-zipfile-0.5.0+dfsg.orig/.travis.yml0000644000000000000000000000355112307716606016602 0ustar rootrootlanguage: cpp compiler: - gcc - clang env: matrix: - NODE_NVM_VERSION="0.10" - NODE_NVM_VERSION="0.8" global: - secure: hBUfRqVPovL7PVOJONI8sakIUtggpM74qMPdi5zaMpJhuV/QWfROOVc05ULEr1P0Fra2WpQ62mp8lfa1NbB6sQfT/8Y6u0lucf9SsIUBJzDrSmfXv2NDgpJn9RQmfsZgLfDuTwRLVROkNSTowUq3tnhDIzX/NyB7uOp1TZNEJ8A= - secure: xWyq1Ys9lpMUVCh73q5YDDfC4nLeeydqIS4S+lJ/t/jUCNHDwe1x5XrxRIALi74qNmHg6eTcOeEW5iot/sf1oUJIA1oPt9iMIMolg9iYWJKWN4E6gWcIigYu9ZDl3GJsHyiNs/dVlZjzY1YKzyvgZ2MRfy4l0rPShCxROoCiCIM= before_install: - COMMIT_MESSAGE=$(git show -s --format=%B $TRAVIS_COMMIT | tr -d '\n') # here we set up the node version on the fly based on the matrix value. # This is done manually so that it is easy to flip the 'language' to # objective-c in another branch (to run the same travis.yml on OS X) - git clone https://github.com/creationix/nvm.git ../.nvm - source ../.nvm/nvm.sh - nvm install $NODE_NVM_VERSION - nvm use $NODE_NVM_VERSION - node --version - npm --version - sudo apt-get -qq update - npm install mocha - npm install aws-sdk install: # test building from source - npm install --build-from-source - npm test - node-pre-gyp package testpackage - npm test before_script: # test publishing and installing from remote if # [publish binary] is present in commit message - PUBLISH_BINARY=false - if [[ ${CXX} == "g++" ]] && test "${COMMIT_MESSAGE#*'[publish binary]'}" != "$COMMIT_MESSAGE"; then echo yes;PUBLISH_BINARY=true; fi; - if [[ $PUBLISH_BINARY == true ]]; then node-pre-gyp publish info; rm -rf {build,lib/binding}; npm install --fallback-to-build=false; npm test; fi - node-pre-gyp clean script: # test building with against shared libzip - make clean - sudo apt-get -qq install libzip-dev - npm install --build-from-source --shared_libzip - npm test after_success: # if success then query and display all published binaries - node-pre-gyp info node-zipfile-0.5.0+dfsg.orig/configure0000755000000000000000000000011512307716606016371 0ustar rootroot#!/bin/sh `npm explore npm -g -- pwd`/bin/node-gyp-bin/node-gyp configure $@node-zipfile-0.5.0+dfsg.orig/LICENSE.txt0000644000000000000000000000310012307716606016302 0ustar rootrootCopyright (c) 2014, Mapbox 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.5.0+dfsg.orig/CHANGELOG.md0000644000000000000000000000042312307716606016275 0ustar rootroot# changelog ## v0.5.0 - Now supporting binary deploy through node-pre-gyp (#42). Run `npm install --build-from-source` now to build from source instead of installing from a binary. ## v0.4.3 - Upgraded libzip to hg at http://hg.nih.at/libzip/rev/66d608d38359 to fix #36node-zipfile-0.5.0+dfsg.orig/bin/0000755000000000000000000000000012307716606015235 5ustar rootrootnode-zipfile-0.5.0+dfsg.orig/bin/unzip.js0000755000000000000000000000142212307716606016742 0ustar rootroot#!/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.5.0+dfsg.orig/test.js0000755000000000000000000000354612307716606016015 0ustar rootroot#!/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.5.0+dfsg.orig/src/0000755000000000000000000000000012307716606015254 5ustar rootrootnode-zipfile-0.5.0+dfsg.orig/src/node_zipfile.cpp0000644000000000000000000003063512307716606020436 0ustar rootroot#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(), ZIP_CHECKCONS, &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(), ZIP_CHECKCONS, &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() , ZIP_CHECKCONS, &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); } #define MAKE_MODULE(_modname) NODE_MODULE( _modname, init) MAKE_MODULE(MODULE_NAME) } node-zipfile-0.5.0+dfsg.orig/src/node_zipfile.hpp0000644000000000000000000000204712307716606020437 0ustar rootroot#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.5.0+dfsg.orig/binding.gyp0000644000000000000000000000254212307716606016623 0ustar rootroot{ 'includes': [ 'deps/common-libzip.gypi' ], 'variables': { 'shared_libzip%':'false', 'shared_libzip_includes%':'/usr/lib', 'shared_libzip_libpath%':'/usr/include' }, 'targets': [ { 'target_name': '<(module_name)', 'conditions': [ ['shared_libzip == "false"', { 'dependencies': [ 'deps/libzip.gyp:libzip' ] }, { 'libraries': [ '-L<@(shared_libzip_libpath)', '-lzip' ], 'include_dirs': [ '<@(shared_libzip_includes)', '<@(shared_libzip_libpath)/libzip/include', ] } ] ], 'defines': [ 'MODULE_NAME=<(module_name)' ], 'sources': [ 'src/node_zipfile.cpp' ], }, { 'target_name': 'action_after_build', 'type': 'none', 'dependencies': [ '<(module_name)' ], 'copies': [ { 'files': [ '<(PRODUCT_DIR)/<(module_name).node' ], 'destination': '<(module_path)' } ], 'conditions': [ ['OS=="win"', { 'copies': [ { 'files': [ '<(PRODUCT_DIR)/libzip.dll' ], 'destination': '<(module_path)' } ] }] ] } ] } node-zipfile-0.5.0+dfsg.orig/Makefile0000755000000000000000000000127712307716606016137 0ustar rootrootall: zipfile.node zipfile.node: PATH=`npm explore npm -g -- pwd`/bin/node-gyp-bin:./node_modules/.bin:$${PATH} && ./node_modules/.bin/node-pre-gyp build clean: @rm -rf ./build rm -rf lib/bindings/ 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.5.0+dfsg.orig/.gitignore0000644000000000000000000000013012307716606016447 0ustar rootrootbuild .lock-wscript .DS_Store *.o *.a deps/libzip-0.10 lib/binding node_modules test/tmpnode-zipfile-0.5.0+dfsg.orig/tools/0000755000000000000000000000000012307716606015625 5ustar rootrootnode-zipfile-0.5.0+dfsg.orig/tools/fix_cpp_style.sh0000755000000000000000000000017112307716606021033 0ustar rootrootecho `pwd` for file in $(find ./src/ -name '*.*') do emacs -batch $file -l `pwd`/tools/cpp.el -f fixup_format done node-zipfile-0.5.0+dfsg.orig/tools/cpp.el0000644000000000000000000000044312307716606016732 0ustar rootroot(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.5.0+dfsg.orig/scripts/0000755000000000000000000000000012307716606016154 5ustar rootrootnode-zipfile-0.5.0+dfsg.orig/scripts/package_osx.sh0000755000000000000000000000072612307716606021004 0ustar rootroot#!/bin/bash CURRENT_DIR="$( cd "$( dirname $BASH_SOURCE )" && pwd )" cd $CURRENT_DIR/../ source ~/.nvm/nvm.sh nvm use 0.10 set -u -e npm install node-gyp npm install aws-sdk export PATH=`pwd`/node_modules/.bin:$PATH function doit { rm -rf build node-pre-gyp clean build package testpackage "$@" npm test ./node_modules/.bin/node-pre-gyp publish info "$@" npm install --fallback-to-build=false npm test } doit nvm use 0.8 doit --target=0.8.26node-zipfile-0.5.0+dfsg.orig/deps/0000755000000000000000000000000012311361775015416 5ustar rootrootnode-zipfile-0.5.0+dfsg.orig/deps/notes.md0000644000000000000000000000017512307716606017075 0ustar rootrootmodified libzip-0.11.1-mod.tar.gz - this patch applied: http://hg.nih.at/libzip/rev/6aeb5008ceeb - lib/zipconf.h removednode-zipfile-0.5.0+dfsg.orig/deps/common-libzip.gypi0000644000000000000000000000007112307716606021067 0ustar rootroot{ 'variables': { 'libzip_version%':'0.11.1' } }node-zipfile-0.5.0+dfsg.orig/package.json0000644000000000000000000000230112307716606016747 0ustar rootroot{ "name" : "zipfile", "version" : "0.5.0", "main" : "./lib/index.js", "description" : "C++ library for handling zipfiles in node", "keywords" : ["zipfile", "uncompress", "unzip", "zlib"], "url" : "http://github.com/mapbox/node-zipfile", "repository" : { "type" : "git", "url" : "git://github.com/mapbox/node-zipfile.git" }, "author" : "Dane Springmeyer ", "contributors" : [], "licenses" : ["BSD"], "dependencies" : { "node-pre-gyp": "0.5.x" }, "bundledDependencies":["node-pre-gyp"], "devDependencies": { "mocha": "*", "mkdirp": "~0.3.0", "jshint" : "~0.5.x" }, "bin" : { "unzip.js" : "./bin/unzip.js" }, "engines" : { "node": ">= 0.6.13 < 0.11.0" }, "scripts" : { "test" : "mocha -R spec", "install" : "node-pre-gyp install --fallback-to-build" }, "binary": { "module_name" : "zipfile", "module_path" : "./lib/binding/", "host" : "https://mapbox-node-binary.s3.amazonaws.com", "remote_path" : "./{module_name}/v{version}", "package_name": "{node_abi}-{platform}-{arch}.tar.gz" } } node-zipfile-0.5.0+dfsg.orig/vcbuild.bat0000644000000000000000000000011612307716606016603 0ustar rootrootrd /q /s build rd /q /s lib\\binding npm install --build-from-source npm test