diff --git a/epub.js b/epub.js index aab8f4b..3d9aafa 100644 --- a/epub.js +++ b/epub.js @@ -1,5 +1,5 @@ var XML2JS = require("xml2js").Parser; -var utillib = require("util"); +var util = require('util'); var EventEmitter = require('events').EventEmitter; try { @@ -66,7 +66,7 @@ function EPub(fname, imageroot, linkroot) { this.linkroot += "/"; } } -utillib.inherits(EPub, EventEmitter); +util.inherits(EPub, EventEmitter); /** * EPub#parse() -> undefined @@ -729,5 +729,25 @@ EPub.prototype.getFile = function (id, callback) { }; +EPub.prototype.readFile = function(filename, options, callback_) { + var callback = arguments[arguments.length - 1]; + + if (util.isFunction(options) || !options) { + this.zip.readFile(filename, callback); + } else if (util.isString(options)) { + // options is an encoding + this.zip.readFile(filename, function(err, data) { + if (err) { + callback(new Error('Reading archive failed')); + return; + } + callback(null, data.toString(options)); + }); + } else { + throw new TypeError('Bad arguments'); + } +}; + + // Expose to the world module.exports = EPub; \ No newline at end of file