Skip to content

Node archive handling

bytes → signature check → plain XML: decode UTF-8 directly
└── zip: find model.xml entry → stream-decode → CRC-32 check → decode UTF-8

extractArchiModelXml accepts raw bytes and returns the model XML text for both file shapes:

import { readFile } from 'node:fs/promises';
import { extractArchiModelXml } from '@cda/archi-semantic-core/archive';
const bytes = await readFile('Model.archimate'); // binary read — never text-decode first
const xml = extractArchiModelXml(bytes);

The function peeks at the file signature:

  • PK (zip) → archive path: localize model.xml in the central directory, inflate it, verify CRC-32, decode UTF-8.
  • anything else → plain-XML path: decode the bytes directly as UTF-8.

Only Stored (uncompressed) and Deflate entries are supported — those are the only two methods Archi ever writes. Any other method throws. The full .archimate archive never needs to be inflated: only the model.xml entry is read, so the memory cost stays proportional to the model’s decoded size (see Working with large models).

ConditionBehavior
Input looks like a zip but has no model.xml entrythrows
Entry uses a method other than Stored/Deflatethrows
CRC-32 mismatch on the decoded entrythrows
Truncated or corrupt zip structurethrows

extractArchiModelXml returns XML only — image bytes stay in the archive. ArchiProfile.imagePath (e.g. "images/abc123.png") and the DiagramModelImageProvider image paths are pointers: to extract a specific binary, open the archive yourself and read the corresponding images/ entry.

The archive path uses Node’s built-in node:zlib — this is why the function lives in the /archive subpath and is not part of the browser-safe root entrypoint. If you need browser-side archive handling, that is a separate package concern, not this one’s.