npm install craycray 
===========
Stream Based EPUB Parser.
As Packagejavascript
var cray = require('cray')('./test1.epub');
// Triggered when the epub contents have been parsed.
cray.queue[0].on('finish', function() {
console.log(parser[0]); // Entire EPUB properties accessible in this json
});
// Triggered when there is something wrong with the file stream
cray.queue[0].on('error', function(err) {
console.log(err);
});
`
$3
`javascript
//The code example above can be modified to use the parser for multiple files.
var cray = require('cray')(['test1.epub', './test2.epub']);
// It will return an array of Epubs with Event that you can watch as
// described in previous example.
// cray.queue[0] --> 'test1.epub' epub object
// cray.queue[1] --> 'test2.epub' epub object
`
Data Structure
$3
__Important__ - _Accessible only after finish event_
Example
`javascript
// Available din the array object.
// --> cray.queue[0].metadata
// Structure
// Sample -->
/* { language: 'en',
title: 'Accessible EPUB 3',
date: '2012-02-20',
creator: 'Matt Garrish',
contributor:
[ 'O'Reilly Production Services',
'David Futato',
'Robert Romano',
'Brian Sawyer',
'Dan Fauxsmith',
'Karen Montgomery' ],
publisher: 'O'Reilly Media, Inc.',
rights: 'Copyright c 2012 O'Reilly Media, Inc' } */
`
$3
__Important__ - _Accessible only after finish event_
Example
`javascript
// Available in the array object.
// --> cray.queue[0].nav
// Structure
// Sample -->
/* { id: 'htmltoc',
properties: 'nav',
'media-type': 'application/xhtml+xml',
href: 'bk01-toc.xhtml' } */
`
$3
__Important__ - _Accessible only after finish event_
Example
`javascript
// Available in the array object.
// --> cray.queue[0].cover
// Structure
// Sample -->
/ { imagePath: 'covers/9781449328030_lrg.jpg' } /
`
$3
__Important__ - _Accessible only after finish event_
Example
`javascript
// Available in the array object.
// --> cray.queue[0].cover
// Structure {Array}
// Sample -->
/* [ { 'media-type': 'text/css',
id: 'epub-css',
href: 'css/epub.css' },
{ 'media-type': 'text/css',
id: 'epub-tss-css',
href: 'css/synth.css' } ] */
`
$3
__Important__ - _Accessible only after finish event_
Example
`javascript
// Available in the array object.
// --> cray.queue[0].spines
// Structure {Array}
// Sample -->
/* [ { 'media-type': 'text/css',
id: 'epub-css',
href: 'css/epub.css' },
{ 'media-type': 'text/css',
id: 'epub-tss-css',
href: 'css/synth.css' } ] */
`
$3
__Important__ - _Accessible only after finish event_
Contains the folder name where the opf file is located.
Example
`javascript
// Available in the array object.
// --> cray.queue[0].opfRoot
`
Events
1. EPUB:opf:parsed DEPRECATED
This event is triggered when the opf file has been completely traversed by cray. At this point the epub object will contain all the populated data structures regarding the respective epub file.
2. EPUB:error DEPRECATED
Triggered when there is a node fs error w.r.t to the epub file that is parsed.
3. EPUB:invalid DEPRECATED
Triggered when there is an invalid file structure present within the EPUB.
4. READY
Triggered when all epubs in the queue are processed.
`javascript
// Example
var cray = require('cray')(['./test1.epub', 'test2.epub']);
cray.on('READY', function() {
console.log("All processed", cray.queue / This is an array /);
});
`
Command Line Tool
Cray can also be used as a command line utility by __installing__ it globally. As described below.
`bash
npm install -g cray
`
$3
`bash
cray -e test1.epub,fail.epub
┌────────────────────┬───────────┬────────────────────────────────┐
│ Epub Name │ Directory │ Status │
├────────────────────┼───────────┼────────────────────────────────┤
│ test1.epub │ CWD │ Valid │
├────────────────────┼───────────┼────────────────────────────────┤
│ containerFail.epub │ CWD │ Container XML file is missing! │
└────────────────────┴───────────┴────────────────────────────────┘
`
Important Using -v or --verbose, Checks the epub file using IDPF epubcheck tool, requires java to be installed.
#### Help
You can check out the list of options that come along with using Cray by typing the following command.
`bash
cray --help
``