From 5df69ae7d80054305cae30452735c5be89987e28 Mon Sep 17 00:00:00 2001 From: Nemanja Nedeljkovic Date: Wed, 25 Jul 2018 01:16:50 +0200 Subject: [PATCH 1/2] Replace adm-zip with zipread --- .editorconfig | 9 +++++++++ epub.js | 35 ++++++++++++++++++++--------------- package-lock.json | 12 ++++++------ package.json | 4 ++-- 4 files changed, 37 insertions(+), 23 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..bc1f92e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 4 +end_of_line = lf +insert_final_newline = true + diff --git a/epub.js b/epub.js index 5adbf35..fa1381d 100644 --- a/epub.js +++ b/epub.js @@ -3,28 +3,33 @@ var xml2jsOptions = xml2js.defaults['0.1']; var util = 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'); +//try { + //// zipfile is an optional dependency: + //var ZipFile = require("zipfile").ZipFile; +//} catch (err) { + 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); }; -} +//} //TODO: Cache parsed data diff --git a/package-lock.json b/package-lock.json index a4e8799..68c3102 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,14 +1,9 @@ { "name": "epub", - "version": "0.2.0", + "version": "0.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { - "adm-zip": { - "version": "0.4.11", - "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.4.11.tgz", - "integrity": "sha512-L8vcjDTCOIJk7wFvmlEUN7AsSb8T+2JrdP7KINBjzr24TJ5Mwj590sLu3BC7zNZowvJWa/JtPmD8eJCzdtDWjA==" - }, "nan": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/nan/-/nan-2.4.0.tgz", @@ -1068,6 +1063,11 @@ } } } + }, + "zipread": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/zipread/-/zipread-1.3.3.tgz", + "integrity": "sha1-VoSJFfZeAx093vJzg6bT7lhDzkE=" } } } diff --git a/package.json b/package.json index 0112b83..521bc6e 100644 --- a/package.json +++ b/package.json @@ -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" From 67e7822d0be55f9cb0594f23dd034e2358439f63 Mon Sep 17 00:00:00 2001 From: Nemanja Nedeljkovic Date: Wed, 25 Jul 2018 01:23:03 +0200 Subject: [PATCH 2/2] Reenable native zip --- epub.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/epub.js b/epub.js index fa1381d..63ca6ab 100644 --- a/epub.js +++ b/epub.js @@ -3,10 +3,10 @@ var xml2jsOptions = xml2js.defaults['0.1']; var util = require('util'); var EventEmitter = require('events').EventEmitter; -//try { - //// zipfile is an optional dependency: - //var ZipFile = require("zipfile").ZipFile; -//} catch (err) { +try { + // zipfile is an optional dependency: + var ZipFile = require("zipfile").ZipFile; +} catch (err) { var zipread = require("zipread"); var ZipFile = function(filename) { @@ -29,7 +29,7 @@ var EventEmitter = require('events').EventEmitter; var buffer = this.zip.readFileSync(name); return cb(null, buffer); }; -//} +} //TODO: Cache parsed data