feat: parse FSSHTTP table of contents stores

This commit is contained in:
2026-07-22 19:56:31 +02:00
parent 3c3904f896
commit 622f1e94dd
2 changed files with 160 additions and 7 deletions

View File

@@ -6,6 +6,8 @@ import { BinaryReader } from '../binary/BinaryReader.js';
import { readGuid } from '../binary/guid.js';
import type { ParserDiagnostic } from '../model/diagnostics.js';
import { parseDesktopOneNoteTableOfContentsStore } from '../onestore/desktop-store.js';
import type { DesktopOneStore } from '../onestore/desktop-store.js';
import { parseFssHttpOneStore } from '../onestore/fsshttp-store.js';
import {
countObjectReferences,
findProperty,
@@ -13,7 +15,7 @@ import {
} from '../onestore/property-set.js';
import type { ExGuid, ObjectSpace, StoreObject } from '../onestore/types.js';
import { exGuidKey } from '../onestore/types.js';
import { toBytes } from './detect-format.js';
import { detectOneNoteFormat, toBytes } from './detect-format.js';
import { OneNoteParserError } from './error.js';
import type { OneNoteParserLimits } from './limits.js';
import { resolveParserLimits } from './limits.js';
@@ -58,7 +60,7 @@ interface TocContext {
active: Set<string>;
}
/** Parse a desktop revision-store `.onetoc2` without network access. */
/** Parse a supported desktop or FSSHTTPB `.onetoc2` without network access. */
export function parseOneNoteTableOfContents(
input: ArrayBuffer | Uint8Array,
options: ParseOneNoteTableOfContentsOptions = {}
@@ -66,11 +68,7 @@ export function parseOneNoteTableOfContents(
const bytes = toBytes(input);
const limits = resolveParserLimits(options.limits);
const diagnostics: ParserDiagnostic[] = [];
const store = parseDesktopOneNoteTableOfContentsStore(
bytes,
limits,
diagnostics
);
const store = parseTableOfContentsStore(bytes, limits, diagnostics);
const space = store.rootObjectSpace;
const rootId = space.roots.get(1);
if (!rootId) {
@@ -110,6 +108,25 @@ export function parseOneNoteTableOfContents(
};
}
function parseTableOfContentsStore(
bytes: Uint8Array,
limits: OneNoteParserLimits,
diagnostics: ParserDiagnostic[]
): DesktopOneStore {
const store =
detectOneNoteFormat(bytes).kind === 'fsshttp-one'
? parseFssHttpOneStore(bytes, limits, diagnostics)
: parseDesktopOneNoteTableOfContentsStore(bytes, limits, diagnostics);
if (store.kind !== 'table-of-contents') {
throw new OneNoteParserError(
'INVALID_FORMAT',
'Expected a OneNote table of contents, found a section',
{ structure: 'OneStore table of contents' }
);
}
return store;
}
function parseChildren(
context: TocContext,
parent: StoreObject,