@eigenpal/docx-editor-core/docx/rezip
DOCX Repacker - Repack modified document into valid DOCX
Takes a Document with modified content and creates a new DOCX file by updating document.xml while preserving all other files from the original ZIP archive.
This ensures round-trip fidelity: - styles.xml, theme1.xml, fontTable.xml remain untouched - Media files preserved - Relationships preserved - Only document.xml is updated with new content
OOXML Package Structure: - [Content_Types].xml - Content type declarations - _rels/.rels - Package relationships - word/document.xml - Main document (modified) - word/styles.xml - Styles (preserved) - word/theme/theme1.xml - Theme (preserved) - word/numbering.xml - Numbering (preserved) - word/fontTable.xml - Font table (preserved) - word/settings.xml - Settings (preserved) - word/header*.xml - Headers (preserved) - word/footer*.xml - Footers (preserved) - word/footnotes.xml - Footnotes (preserved) - word/endnotes.xml - Endnotes (preserved) - word/media/* - Media files (preserved) - word/_rels/document.xml.rels - Document relationships (preserved) - docProps/* - Document properties (preserved)
Orchestrators (repackDocx, selective updates, validation, create-empty) live here. Per-domain helpers — part enumeration, new-image registration, new-hyperlink registration, header/footer & comment packaging, and the empty-DOCX template — live under ./rezip/.
Functions (15)
addMediafunctionSource ↗
Add a media file to the DOCX
declare function addMedia(originalBuffer: ArrayBuffer, filename: string, data: ArrayBuffer, mimeType: string): Promise<{
buffer: ArrayBuffer;
rId: string;
path: string;
}>;addRelationshipfunctionSource ↗
Add a new relationship to document.xml.rels
declare function addRelationship(originalBuffer: ArrayBuffer, relationship: {
type: string;
target: string;
targetMode?: 'External' | 'Internal';
}): Promise<{
buffer: ArrayBuffer;
rId: string;
}>;applyUpdatesToZipfunctionSource ↗
Apply file updates to an already-loaded JSZip instance and generate the output. Use this when the zip is already loaded to avoid a redundant decompression pass.
declare function applyUpdatesToZip(zip: JSZip, updates: Map<string, string | ArrayBuffer>, options?: RepackOptions): Promise<ArrayBuffer>;collectHeaderFooterUpdatesfunctionSource ↗
Collect serialized header/footer XML updates from the document model. Uses the relationship map to resolve rId → filename.
declare function collectHeaderFooterUpdates(doc: Document): Map<string, string>;createDocxfunctionSource ↗
Create a new DOCX from a Document (without requiring original buffer)
declare function createDocx(doc: Document): Promise<ArrayBuffer>;createEmptyDocxfunctionSource ↗
Create a new empty DOCX file.
declare function createEmptyDocx(): Promise<ArrayBuffer>;findMaxRIdfunctionSource ↗
Find the highest rId number in a relationships XML string.
declare function findMaxRId(relsXml: string): number;isDocxBufferfunctionSource ↗
Check if buffer looks like a DOCX file (quick check)
declare function isDocxBuffer(buffer: ArrayBuffer): boolean;repackDocxfunctionSource ↗
Repack a Document into a valid DOCX file
declare function repackDocx(doc: Document, options?: RepackOptions): Promise<ArrayBuffer>;repackDocxFromRawfunctionSource ↗
Repack a Document using raw content for more control
declare function repackDocxFromRaw(doc: Document, rawContent: RawDocxContent, options?: RepackOptions): Promise<ArrayBuffer>;updateCorePropertiesfunctionSource ↗
Update core properties XML with new modification date
declare function updateCoreProperties(corePropsXml: string, options: {
updateModifiedDate?: boolean;
modifiedBy?: string;
}): string;updateDocumentXmlfunctionSource ↗
Update only document.xml in a DOCX buffer (minimal changes)
declare function updateDocumentXml(originalBuffer: ArrayBuffer, newDocumentXml: string, options?: RepackOptions): Promise<ArrayBuffer>;updateMultipleFilesfunctionSource ↗
Update multiple files in a DOCX buffer
declare function updateMultipleFiles(originalBuffer: ArrayBuffer, updates: Map<string, string | ArrayBuffer>, options?: RepackOptions): Promise<ArrayBuffer>;updateXmlFilefunctionSource ↗
Update a specific XML file in a DOCX buffer
declare function updateXmlFile(originalBuffer: ArrayBuffer, path: string, content: string, options?: RepackOptions): Promise<ArrayBuffer>;validateDocxfunctionSource ↗
Validate that a buffer is a valid DOCX file
declare function validateDocx(buffer: ArrayBuffer): Promise<{
valid: boolean;
errors: string[];
warnings: string[];
}>;Interfaces (1)
RepackOptionsinterfaceSource ↗
Options for repacking DOCX
interface RepackOptions| Member | Type | Summary |
|---|---|---|
| compressionLevel? | number | Compression level (0-9, default: 6) |
| modifiedBy? | string | Custom modifier name for lastModifiedBy |
| updateModifiedDate? | boolean | Whether to update modification date in docProps/core.xml |
Variables (4)
COMMENTS_CONTENT_TYPEconstSource ↗
Header/Footer & Comment Packaging
Serialize modified headers, footers, and comments back into the ZIP and ensure each new part is registered in [Content_Types].xml and the document's rels file. Without this step Word silently drops parts that the editor inserted into a previously-blank document (#274).
COMMENTS_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml"COMMENTS_EXTENDED_CONTENT_TYPEconstSource ↗
COMMENTS_EXTENDED_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml"COMMENTS_EXTENSIBLE_CONTENT_TYPEconstSource ↗
COMMENTS_EXTENSIBLE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtensible+xml"COMMENTS_IDS_CONTENT_TYPEconstSource ↗
COMMENTS_IDS_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsIds+xml"