[v0.1.5] Optionnally rely on pure-JS zip dependency
This commit is contained in:
parent
aef37a5dc3
commit
0862fd2da0
@ -8,6 +8,11 @@
|
||||
|
||||
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
|
||||
|
||||
var EPub = require("epub");
|
||||
|
23
epub.js
23
epub.js
@ -3,6 +3,29 @@ var XML2JS = require("xml2js").Parser;
|
||||
var utillib = require("util");
|
||||
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
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "epub",
|
||||
"description": "Parse ePub electronic book files with Node.JS",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"author": "Andris Reinman",
|
||||
"contributors": [
|
||||
{
|
||||
@ -27,9 +27,12 @@
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"zipfile": "^0.5.0",
|
||||
"adm-zip": "^0.4.4",
|
||||
"xml2js": "~0.1.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"zipfile": "^0.5.0"
|
||||
},
|
||||
"engine": [
|
||||
"node >=0.3.0"
|
||||
],
|
||||
|
Reference in New Issue
Block a user