-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as fflate from 'fflate'; | ||
import { XMLBuilder } from 'fast-xml-parser'; | ||
|
||
import type { Epubook } from './epub'; | ||
|
||
const MIMETYPE = fflate.strToU8('application/epub+zip'); | ||
|
||
export async function bundle(epub: Epubook) { | ||
return new Promise((res, rej) => { | ||
fflate.zip( | ||
{ | ||
mimetype: MIMETYPE, | ||
'META-INF': { | ||
'container.xml': fflate.strToU8('') | ||
} | ||
}, | ||
{ | ||
level: 1, | ||
mtime: new Date() | ||
}, | ||
(err, data) => { | ||
if (err) { | ||
rej(err); | ||
} else { | ||
res(data); | ||
} | ||
} | ||
); | ||
}); | ||
} | ||
|
||
export function makeContainer(epub: Epubook) { | ||
const builder = new XMLBuilder({ format: true, ignoreAttributes: false }); | ||
return builder.build({ | ||
'?xml': [{ '#text': '' }], | ||
container: { | ||
version: '1.0', | ||
xmlns: 'urn:oasis:names:tc:opendocument:xmlns:container' | ||
} | ||
}); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export class Epubook { | ||
constructor() {} | ||
|
||
async bundle() { | ||
const { bundle } = await import('./bundle'); | ||
return await bundle(this); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
|
||
import { Epubook } from '../src/epub'; | ||
import { makeContainer } from '../src/bundle'; | ||
|
||
describe('Bundle Epub', () => { | ||
it('generate container.xml', () => { | ||
const res = makeContainer(new Epubook()); | ||
console.log(res); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.