2.9 KiB
2.9 KiB
manager-stream
Purpose
Free-function implementation of PackedResourceManager.loadStream,
factored out of manager.ts so the class stays under the CLAUDE.md
§3 300-line hard cap. The function drives the loader's streaming
iterator, inserts each decoded entry into the manager's cache, and
emits a load event before yielding the entry to the caller — so
streaming consumers see exactly the same cache-priming behaviour as
batch consumers.
Features
- Threads the manager's default
MessageResolverand feature-flag provider through every loader call viabuildLoaderOptions. - Inserts each yielded entry into the cache before yielding so a
consumer that calls
manager.load(inputUrl)immediately after receiving an entry hits the cache (no second fetch). AbortSignalpropagation is honoured at entry time (viamanager._checkAbortedExt) and re-honoured by the underlyingloader.loadStreamiterator at each yield.- Per-entry options (
StreamLoadEntry.options) override the manager- level options, so a single stream can mixverifyKeys, keyrings, and mime allow-lists.
Usage: Basic Example
import { createPackedResourceManager } from "@suaveplan/packer-browser";
const manager = createPackedResourceManager();
for await (const entry of manager.loadStream([
"/asset-a.packed",
"/asset-b.packed",
])) {
console.info("decoded", entry.inputUrl, "→", entry.url);
}
Usage: Advanced Example
import {
createPackedResourceManager,
MemoryKeyring,
} from "@suaveplan/packer-browser";
const manager = createPackedResourceManager();
const keyring = new MemoryKeyring({ "v1": new Uint8Array(32).fill(7) });
const ac = new AbortController();
for await (const entry of manager.loadStream(
[
{ url: "/plain.packed" },
{ url: "/encrypted.packed", options: { keyring } },
],
{ signal: ac.signal }
)) {
if (entry.inputUrl === "/plain.packed") ac.abort();
process(entry);
}
API Reference
managerLoadStream(manager, opts, inputs)— internal entrypoint used byPackedResourceManager.loadStream. Not part of the package barrel.ManagerStreamedEntry—{ url, inputUrl, metadata }.
Implementation Notes
- The function takes the
inputsarray as the trailing parameter so the manager can passoptsearly; this keeps the method signature inmanager.tsto a single line and avoids type-juggling in the delegation. _streamInsert,_getDefaultResolver, and_checkAbortedExton the manager are intentionally_-prefixed: they exist only to give this free function access to the manager's internals without exposing cache/resolver/abort plumbing on the public surface. They are not in the package barrel.- The manager's
cacheHit/cacheMissevents are NOT emitted from the streaming path — every streamed entry is, by definition, a fresh load. Consumers that need pre-stream cache lookups should combinecache.has(...)with a batchload.