index.js
function _bundleEPUB(config, done) {
    
    var epubconfig = config.akashacmsEPUB;
    
    var archive = archiver('zip');
    
    var output = fs.createWriteStream(config.akashacmsEPUB.bookmetadata.epub);
            
    output.on('close', function() {
        logger.info(archive.pointer() + ' total bytes');
        logger.info('archiver has been finalized and the output file descriptor has closed.');
        done();
    });
    
    archive.on('error', function(err) {
      logger.info('*********** BundleEPUB ERROR '+ err);
      done(err);
    });
    
    archive.pipe(output);
    
    // The mimetype file must be the first entry, and must not be compressed
    archive.append(
        fs.createReadStream(path.join(config.root_out, "mimetype")),
        { name: "mimetype", store: true });
    archive.append(
        fs.createReadStream(path.join(config.root_out, "META-INF", "container.xml")),
        { name: path.join("META-INF", "container.xml") });
    archive.append(
        fs.createReadStream(path.join(config.root_out, config.akashacmsEPUB.bookmetadata.opf)),
        { name: config.akashacmsEPUB.bookmetadata.opf });
    // archive.append(
    //     fs.createReadStream(path.join(config.root_out, config.akashacmsEPUB.files.ncx)),
    //    { name: config.akashacmsEPUB.files.ncx });
    
    // logger.info(util.inspect(config.akashacmsEPUB.manifest));
    async.eachSeries(config.akashacmsEPUB.manifest,
        function(item, next) {
            // logger.info(util.inspect(item));
            // if (item.spinetoc !== true) { // this had been used to skip the NCX file
            archive.append(
                fs.createReadStream(path.join(config.root_out, item.href)),
                { name: item.href }
            );
            // }
            next();
        },
        function(err) {
            if (err) logger.error(err);
            logger.info('before finalize');
            archive.finalize();
        });
}
function _bundleEPUB(config, done) {
    
    var epubconfig = config.akashacmsEPUB;
    
    var archive = archiver('zip');
    
    var output = fs.createWriteStream(config.akashacmsEPUB.bookmetadata.epub);
            
    output.on('close', function() {
        logger.info(archive.pointer() + ' total bytes');
        logger.info('archiver has been finalized and the output file descriptor has closed.');
        done();
    });
    
    archive.on('error', function(err) {
      logger.info('*********** BundleEPUB ERROR '+ err);
      done(err);
    });
    
    archive.pipe(output);
    
    // The mimetype file must be the first entry, and must not be compressed
    archive.append(
        fs.createReadStream(path.join(config.root_out, "mimetype")),
        { name: "mimetype", store: true });
    archive.append(
        fs.createReadStream(path.join(config.root_out, "META-INF", "container.xml")),
        { name: path.join("META-INF", "container.xml") });
    archive.append(
        fs.createReadStream(path.join(config.root_out, config.akashacmsEPUB.bookmetadata.opf)),
        { name: config.akashacmsEPUB.bookmetadata.opf });
    // archive.append(
    //     fs.createReadStream(path.join(config.root_out, config.akashacmsEPUB.files.ncx)),
    //    { name: config.akashacmsEPUB.files.ncx });
    
    // logger.info(util.inspect(config.akashacmsEPUB.manifest));
    async.eachSeries(config.akashacmsEPUB.manifest,
        function(item, next) {
            // logger.info(util.inspect(item));
            // if (item.spinetoc !== true) { // this had been used to skip the NCX file
            archive.append(
                fs.createReadStream(path.join(config.root_out, item.href)),
                { name: item.href }
            );
            // }
            next();
        },
        function(err) {
            if (err) logger.error(err);
            logger.info('before finalize');
            archive.finalize();
        });
}
function _bundleEPUB ( config , done ) { var epubconfig = config . akashacmsEPUB ; var archive = archiver ( 'zip' ) ; var output = fs . createWriteStream ( config . akashacmsEPUB . bookmetadata . epub ) ; output . on ( 'close' , function ( ) { logger . info ( archive . pointer ( ) + ' total bytes' ) ; logger . info ( 'archiver has been finalized and the output file descriptor has closed.' ) ; done ( ) ; } ) ; archive . on ( 'error' , function ( err ) { logger . info ( '*********** BundleEPUB ERROR ' + err ) ; done ( err ) ; } ) ; archive . pipe ( output ) ; // The mimetype file must be the first entry, and must not be compressed archive . append ( fs . createReadStream ( path . join ( config . root_out , "mimetype" ) ) , { name : "mimetype" , store : true } ) ; archive . append ( fs . createReadStream ( path . join ( config . root_out , "META-INF" , "container.xml" ) ) , { name : path . join ( "META-INF" , "container.xml" ) } ) ; archive . append ( fs . createReadStream ( path . join ( config . root_out , config . akashacmsEPUB . bookmetadata . opf ) ) , { name : config . akashacmsEPUB . bookmetadata . opf } ) ; // archive.append( //     fs.createReadStream(path.join(config.root_out, config.akashacmsEPUB.files.ncx)), //    { name: config.akashacmsEPUB.files.ncx }); // logger.info(util.inspect(config.akashacmsEPUB.manifest)); async . eachSeries ( config . akashacmsEPUB . manifest , function ( item , next ) { // logger.info(util.inspect(item)); // if (item.spinetoc !== true) { // this had been used to skip the NCX file archive . append ( fs . createReadStream ( path . join ( config . root_out , item . href ) ) , { name : item . href } ) ; // } next ( ) ; } , function ( err ) { if ( err ) logger . error ( err ) ; logger . info ( 'before finalize' ) ; archive . finalize ( ) ; } ) ; }
Construct the .epub file
Construct the . epub file