Last active
August 31, 2024 13:00
-
-
Save Amice13/a7ffc3b1e43d14861c97eb937128decb to your computer and use it in GitHub Desktop.
Revisions
-
Amice13 revised this gist
Aug 31, 2024 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,6 @@ const fs = require('fs') const path = require('path') const source = 'filename.fb2' const targetFolder = 'result' @@ -9,7 +10,8 @@ if (!fs.existsSync('result')) fs.mkdirSync(targetFolder) const pattern = /<binary[^>]*?id="([^"]*)"[^>]*?>(.*?)<\/binary>/gs const matches = xml.matchAll(pattern) for (const match of matches) { const [_, filename, content] = [...match] const filePath = path.join(targetFolder, filename) fs.writeFileSync(filePath, Buffer.from(content, 'base64')) } -
Amice13 created this gist
Aug 31, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ const fs = require('fs') const path = require('path') const source = 'filename.fb2' const targetFolder = 'result' const xml = fs.readFileSync(source).toString() if (!fs.existsSync('result')) fs.mkdirSync(targetFolder) const pattern = /<binary[^>]*?id="([^"]*)"[^>]*?>(.*?)<\/binary>/gs const matches = xml.matchAll(pattern) for (let match of matches) { const [_, filename, content] = [...match] fs.writeFileSync(path.join(targetFolder, filename), Buffer.from(content, 'base64')) }