import { Relationship } from './relationships.js'; /** * Resource caps applied while unzipping a package — a defence against * decompression ("zip") bombs and pathological archives. Generous defaults that * never reject a legitimate office document; tighten for untrusted input. */ export interface OpcOpenOptions { /** Reject an archive whose raw (compressed) size exceeds this (default 128 MiB). */ readonly maxArchiveBytes?: number; /** Reject any single entry declaring an uncompressed size over this (default 256 MiB). */ readonly maxEntryBytes?: number; /** Reject if the total declared uncompressed size exceeds this (default 512 MiB). */ readonly maxTotalBytes?: number; /** Reject archives with more than this many entries (default 65 536). */ readonly maxEntries?: number; } /** * An opened OPC package (ECMA-376 Part 2): a ZIP archive's parts plus its * package-level relationships, with helpers to look up parts, resolve part * relationships, and find the main document part. */ export declare class OpcPackage { private readonly parts; private readonly rootRelationships; /** * @param parts The package parts keyed by ZIP-convention path (no leading slash). * @param rootRelationships The package-level relationships from `_rels/.rels`. */ private constructor(); private readonly relsCache; private folded; /** * Unzip and validate a package's bytes. Rejects an OLE compound file (an * encrypted OOXML container or a legacy binary `.doc`/`.xls`) and enforces the * zip-bomb caps from `options`. * * @throws Error when the bytes are not a ZIP package, a cap is exceeded, or * `_rels/.rels` is missing. */ static open(buffer: Uint8Array, options?: OpcOpenOptions): OpcPackage; /** * The bytes of the part at `path`, or undefined when absent. * * OPC part names are compared case-insensitively (ISO/IEC 29500-2 §9.1.1.1), * so two names differing only in case are the SAME part. Producers do mix * them: 123233_charts.xlsx writes `xl/worksheets/Sheet1.xml` and its * relationships as `_rels/sheet1.xml.rels`, and an exact lookup found no * relationships for that sheet at all — which cost it four charts, silently, * because a sheet with no drawing rel is indistinguishable from one with no * drawing. An exact hit still wins; the fold is only a fallback. */ getPart(path: string): Uint8Array | undefined; /** Parts keyed by their case-folded path, built once on first miss. */ private foldedParts; /** * The bytes of the part at `path`. * * @throws Error when the part is absent. */ requirePart(path: string): Uint8Array; /** Every part path in the package (ZIP convention, no leading slash). */ listParts(): Array; /** * The relationships of the part at `partPath` (ECMA-376 Part 2 §9.3.4). For a * part at `dir/name.ext` they live at `dir/_rels/name.ext.rels`. Returns `[]` * if the rels part is absent. Parsed rels are cached per part. */ getPartRelationships(partPath: string): ReadonlyArray; /** * Resolve a relationship against its source part and return the related part's * resolved path + data (Internal relationships only). External relationships * (e.g. http hyperlinks) and unresolvable targets return undefined. */ resolveRelatedPart(sourcePartPath: string, relationship: Relationship): { readonly path: string; readonly data: Uint8Array; } | undefined; /** * The path of the main document part, from the package's single * `officeDocument` relationship (ECMA-376 Part 2 §11.1). * * @throws Error when there is no such relationship, or more than one. */ getMainDocumentPath(): string; /** * The main document part's path and bytes. * * @throws Error when the officeDocument relationship is missing/ambiguous or * the part it points at is absent. */ getMainDocument(): { path: string; data: Uint8Array; }; }