123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- const fs = require("fs");
- const xml2js = require("xml2js");
- const { EPub } = require("epub2");
- // 读取 toc.ncx 文件
- // fs.readFile('./test2_副本/OEBPS/toc.ncx', 'utf8', (err, data) => {
- // if (err) {
- // console.error("Error reading the file:", err);
- // return;
- // }
- // // 使用 xml2js 解析 XML 数据
- // const parser = new xml2js.Parser({ explicitArray: false, mergeAttrs: true });
- // parser.parseString(data, (err, result) => {
- // if (err) {
- // console.error("Error parsing the XML:", err);
- // return;
- // }
- // console.log(20, result);
- // // 转换结果为 JSON 格式
- // const jsonResult = JSON.stringify(result, null, 2);
- // // 输出 JSON 数据
- // console.log(jsonResult);
- // // 如果需要将 JSON 保存为文件,可以使用 fs.writeFile()
- // fs.writeFile('output.json', jsonResult, (err) => {
- // if (err) {
- // console.error("Error writing JSON file:", err);
- // } else {
- // console.log("JSON data saved to output.json");
- // }
- // });
- // });
- // });
- // 先处理
- // 读取 OEBPS/Text/chapter396.html 文件
- fs.readFile(
- "./book/test2/OEBPS/Text/:::::::::::::::::::::*:*:::***::.html",
- // "./book/test/OEBPS/Text/chapter396.html",
- "utf8",
- (err, data) => {
- if (err) {
- console.error("Error reading the file:", err);
- return;
- }
- console.log(4545, data);
- // 使用 xml2js 解析 XML 数据
- /* const parser = new xml2js.Parser({ explicitArray: false, mergeAttrs: true });
- parser.parseString(data, (err, result) => {
- if (err) {
- console.error("Error parsing the XML:", err);
- return;
- }
- // 转换结果为 JSON 格式
- const jsonResult = JSON.stringify(result, null, 2);
- // 输出 JSON 数据
- console.log(jsonResult);
- // 如果需要将 JSON 保存为文件,可以使用 fs.writeFile()
- fs.writeFile('output.json', jsonResult, (err) => {
- if (err) {
- console.error("Error writing JSON file:", err);
- } else {
- console.log("JSON data saved to output.json");
- }
- });
- }); */
- }
- );
- // (async () => {
- // // https://github.com/bluelovers/ws-epub/blob/master/packages/epub2/test/example/example2.ts
- // const epub = await EPub.createAsync("./book/test2.epub", null, "");
- // // let imgs = epub.listImage();
- // // console.log(imgs);
- // console.log(78, epub.spine.contents);
- // await epub.getChapterAsync(epub.spine.contents[2].id).then(function (data) {
- // console.log("\nFIRST CHAPTER:\n");
- // console.log(data); // first 512 bytes
- // });
- // })();
|