13 lines
535 B
JavaScript
13 lines
535 B
JavaScript
import { strFromU8, unzipSync } from 'fflate'
|
|
|
|
// An ODT document is a zip archive; its body lives in `content.xml`. Only the
|
|
// requested entry is inflated. A corrupt archive makes fflate throw - the CLI
|
|
// catches it and moves on to the next file, so one bad document never stops the
|
|
// whole import.
|
|
export function readOdtEntry(buffer, entryName) {
|
|
const entries = unzipSync(new Uint8Array(buffer), {
|
|
filter: ({ name }) => name === entryName
|
|
})
|
|
const entry = entries[entryName]
|
|
return entry ? strFromU8(entry) : null
|
|
}
|