[v0.1.5] Optionnally rely on pure-JS zip dependency

This commit is contained in:
Julien Chaumond 2014-04-02 12:50:34 +02:00
parent aef37a5dc3
commit 0862fd2da0
3 changed files with 33 additions and 2 deletions

View File

@ -8,6 +8,11 @@
npm install epub npm install epub
Or, if you want a pure-JS version (useful if used in a Node-Webkit app for example):
npm install epub --no-optional
## Usage ## Usage
var EPub = require("epub"); var EPub = require("epub");

23
epub.js
View File

@ -3,6 +3,29 @@ var XML2JS = require("xml2js").Parser;
var utillib = require("util"); var utillib = require("util");
var EventEmitter = require('events').EventEmitter; var EventEmitter = require('events').EventEmitter;
try {
// zipfile is an optional dependency:
var ZipFile = require("zipfile").ZipFile;
} catch (err) {
// Mock zipfile using pure-JS adm-zip:
var AdmZip = require('adm-zip');
var ZipFile = function(filename) {
this.admZip = new AdmZip(filename);
this.names = this.admZip.getEntries().map(function(zipEntry) {
return zipEntry.entryName;
});
this.count = this.names.length;
};
ZipFile.prototype.readFile = function(name, cb) {
this.admZip.readFileAsync(this.admZip.getEntry(name), function(buffer, error) {
// `error` is bogus right now, so let's just drop it.
// see https://github.com/cthackers/adm-zip/pull/88
return cb(null, buffer);
});
};
}
//TODO: Cache parsed data //TODO: Cache parsed data
/** /**

View File

@ -1,7 +1,7 @@
{ {
"name": "epub", "name": "epub",
"description": "Parse ePub electronic book files with Node.JS", "description": "Parse ePub electronic book files with Node.JS",
"version": "0.1.4", "version": "0.1.5",
"author": "Andris Reinman", "author": "Andris Reinman",
"contributors": [ "contributors": [
{ {
@ -27,9 +27,12 @@
} }
], ],
"dependencies": { "dependencies": {
"zipfile": "^0.5.0", "adm-zip": "^0.4.4",
"xml2js": "~0.1.0" "xml2js": "~0.1.0"
}, },
"optionalDependencies": {
"zipfile": "^0.5.0"
},
"engine": [ "engine": [
"node >=0.3.0" "node >=0.3.0"
], ],