Class: InMemorySpoolReader
Defined in: batteries/storage/in_memory/index.ts:43
Sync in-memory @nhtio/adk!SpoolReader over a byte-faithful Uint8Array body.
Remarks
Stores the raw bytes and decodes them as UTF-8 once at construction, then splits the decoded string on \n and caches the resulting line array. All four SpoolReader methods resolve synchronously from the cache — no I/O happens after construction. byteLength() reports the true stored byte count (not the decoded character count), so it stays correct for multi-byte content; line()/readAll() operate on the decoded text.
The reader accepts a string or a Uint8Array. A string is encoded as UTF-8 for the byte count; a Uint8Array is held byte-faithfully (no lossy re-encode) and decoded for text reads.
Empty input yields a reader with lineCount() === 0 and byteLength() === 0. A trailing newline produces a final empty line: "a\nb\n".split('\n') === ['a', 'b', '']. This matches the JavaScript String.prototype.split contract and lets a lineCount() consumer distinguish "two lines, no trailing newline" from "two lines, trailing newline".
Implements
Constructors
Constructor
new InMemorySpoolReader(content: string | Uint8Array<ArrayBufferLike>): InMemorySpoolReader;Defined in: batteries/storage/in_memory/index.ts:48
Parameters
| Parameter | Type |
|---|---|
content | string | Uint8Array<ArrayBufferLike> |
Returns
InMemorySpoolReader
Methods
byteLength()
byteLength(): number;Defined in: batteries/storage/in_memory/index.ts:63
Returns the total number of bytes in the underlying data.
Returns
number
The byte length of the underlying data.
Remarks
Used for reporting and token-estimation purposes. Byte length is distinct from character length for multi-byte encodings.
Implementation of
line()
line(index: number): string | undefined;Defined in: batteries/storage/in_memory/index.ts:59
Returns the line at the given 0-based index, or undefined when out of range.
Parameters
| Parameter | Type | Description |
|---|---|---|
index | number | 0-based line index. |
Returns
string | undefined
The raw line string (without trailing newline), or undefined.
Implementation of
lineCount()
lineCount(): number;Defined in: batteries/storage/in_memory/index.ts:67
Returns the total number of lines in the underlying data.
Returns
number
The total line count.
Remarks
Required so consumers know when to stop iterating; the line count must remain stable for the lifetime of the reader.
Implementation of
readAll()
readAll(): string;Defined in: batteries/storage/in_memory/index.ts:71
Returns the full underlying content as a single decoded string, byte-faithful to the source.
Returns
string
The full underlying content as a single string.
Remarks
Unlike SpoolReader.line, this method preserves trailing newlines and any non-\n line terminators (e.g. \r\n) present in the original bytes. It is the primitive that powers SpooledArtifact.asString() — the round-trip-faithful alternative to assembling the artifact body from per-line reads.
Implementations should make this O(n) in the size of the underlying data and may cache the result if the read source is durable. Streaming implementations may choose not to cache.