Fixes patchDocument for files with binary content

This commit is contained in:
Ewout Kleinsmann
2023-03-17 16:30:35 +01:00
parent 33332bcf66
commit 71953cf45a

View File

@ -68,7 +68,14 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO
const hyperlinkRelationshipAdditions: IHyperlinkRelationshipAddition[] = [];
let hasMedia = false;
const binaryContentMap = new Map<string, Buffer>();
for (const [key, value] of Object.entries(zipContent.files)) {
if (!key.endsWith('.xml') && !key.endsWith('.rels')) {
binaryContentMap.set(key, await value.async("nodebuffer"))
continue;
}
const json = toJson(await value.async("text"));
if (key.startsWith("word/") && !key.endsWith(".xml.rels")) {
const context: IContext = {
@ -196,6 +203,10 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO
zip.file(key, output);
}
for (const [key, value] of binaryContentMap) {
zip.file(key, value);
}
for (const { stream, fileName } of file.Media.Array) {
zip.file(`word/media/${fileName}`, stream);
}