Simple node.js library to read entries inside an epub container.
$ npm install --save epub-ocf
var ocf = require('epub-ocf');
ocf('example.epub', function(err, container) { // ocf is an alias for ocf.zip
container.readEntry("META-INF/container.xml", function(err, data) {
console.log(err, data);
});
});
You can also create a container object from extracted epub directories.
ocf.dir('path/to/extracted/epub/directory/', function(err, container) {});
Or, epub directories served via http:
ocf.http('http://my.ebooks.service.org/ebook2/', function(err, container) {});
epub-ocf library can also guess which container method to use by examining the given uri.
// a Zip container
ocf.open('path/to/book.epub', function(err, container) {});
// a Directory container
ocf.open('path/to/book-dir', function(err, container) {});
// a Http container
ocf.open('http://my.ebooks.service.org/ebook2/', function(err, container) {});
All container objects have readEntry
, createReadStream
and rootfiles
methods.
Returns the contents of entry.
container.readEntry('META-INF/container.xml', function(err, content) {
console.log(content);
});
Creates a readable stream for the entry.
var stream = container.createEntryStream('EPUB/images/cover.jpg');
stream.pipe(process.stdout);
Returns an array of rootfiles by parsing the META-INF/container.xml
container.rootfiles(function(err, files) {
console.log(files); // [ 'EPUB/package.opf' ]
});
$ git clone https://github.com/glkz/epub-ocf.git
$ cd epub-ocf
$ npm install
$ npm test
See the LICENSE file.