Last active
October 10, 2020 09:41
-
-
Save ncwhale/01e64d6097f92b095d1d725e99c82dac to your computer and use it in GitHub Desktop.
Node.js script for pack .epub resources.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const path = require('path') | |
const archiver = require('archiver') | |
var base_path = './epubs' | |
async function main() { | |
const dir = await fs.promises.opendir(base_path) | |
const books = {} | |
for await (const ent of dir) { | |
if (ent.isDirectory()) { | |
books[ent.name] = false | |
} | |
} | |
for (name in books) { | |
const output = fs.createWriteStream(path.join(base_path, `${name}.epub`)) | |
const archive = archiver('zip', { | |
zlib: { level: 9 } | |
}) | |
output.on('close', () => { | |
console.log(`${name}.epub ${archive.pointer()} bytes`) | |
}) | |
output.on('error', (err) => { | |
throw err; | |
}) | |
archive.pipe(output) | |
archive.append("application/epub+zip", { name: 'mimetype', store: true }) | |
archive.directory(path.join(base_path, name), false) | |
archive.finalize() | |
} | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment