Fixes patchDocument for files with binary content
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user