Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace adm-zip with zipread #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true

25 changes: 15 additions & 10 deletions epub.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,27 @@ 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 zipread = require("zipread");

var ZipFile = function(filename) {
this.admZip = new AdmZip(filename);
this.names = this.admZip.getEntries().map(function(zipEntry) {
return zipEntry.entryName;
var zip = zipread(filename);

this.zip = zip;

var files = zip.files;

files = Object.values(files).filter((file) => {
return !file.dir;
}).map((file) => {
return file.name;
});

this.names = files;
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);
});
var buffer = this.zip.readFileSync(name);
return cb(null, buffer);
};
}

Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"books"
],
"dependencies": {
"adm-zip": "^0.4.11",
"xml2js": "^0.4.19"
"xml2js": "^0.4.19",
"zipread": "^1.3.3"
},
"optionalDependencies": {
"zipfile": "^0.5.11"
Expand Down