Class: InMemorySpoolReader
Sync in-memory @nhtio/adk!SpoolReader over a string body.
Remarks
Splits the supplied content on \n at construction time and caches the resulting line array plus the UTF-8 byte length. All three SpoolReader methods resolve synchronously from the cache — no I/O happens after construction.
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): InMemorySpoolReader;Parameters
| Parameter | Type |
|---|---|
content | string |
Returns
InMemorySpoolReader
Methods
byteLength()
byteLength(): number;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;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;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;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.