feat: extract complete multi-cabinet sets

This commit is contained in:
2026-07-22 19:40:45 +02:00
parent b492a529ae
commit 538318c697
15 changed files with 1911 additions and 59 deletions

View File

@@ -7,10 +7,13 @@ import type {
import type { ParserDiagnostic } from '../model/diagnostics.js';
import { checkCancellation } from './cancellation.js';
import { extractCabinet } from './cabinet.js';
import { extractCabinetSet } from './cabinet-set.js';
import { diagnosticFromUnknown, OnePkgError, warning } from './errors.js';
import { buildOneNotePackageTree } from './toc-hierarchy.js';
import type {
CabOpenOptions,
CabExtractionResult,
CabSetPart,
ExtractedCabFile,
OnePkgCancellation,
} from './types.js';
@@ -84,6 +87,34 @@ export async function openOneNotePackage(
): Promise<OneNotePackageOpenResult> {
const sourceName = options.sourceName ?? 'notebook.onepkg';
const extraction = await extractCabinet(bytes, options);
return buildOpenedPackage(extraction, sourceName, bytes.byteLength, options);
}
export async function openOneNotePackageSet(
parts: CabSetPart[],
options: OneNotePackageOpenOptions = {}
): Promise<OneNotePackageOpenResult> {
const extraction = await extractCabinetSet(parts, options);
const sourceName =
options.sourceName ??
parts.find((part) => part.fileName.toLowerCase().endsWith('.onepkg'))
?.fileName ??
extraction.parts[0]?.fileName ??
'notebook.onepkg';
return buildOpenedPackage(
extraction,
sourceName,
parts.reduce((sum, part) => sum + part.bytes.byteLength, 0),
options
);
}
async function buildOpenedPackage(
extraction: CabExtractionResult,
sourceName: string,
sourceSize: number,
options: OneNotePackageOpenOptions
): Promise<OneNotePackageOpenResult> {
const diagnostics = [...extraction.diagnostics];
const packageEntries: OneNotePackageEntryDto[] =
extraction.extractedEntries.map((entry) => ({
@@ -173,7 +204,7 @@ export async function openOneNotePackage(
package: {
format: 'onepkg',
sourceName,
sourceSize: bytes.byteLength,
sourceSize,
entries: packageEntries,
sections: packagedSections,
tree: treeResult.tree,