TextRingBuffer
A bounded, in-memory store of UTF-8 encoded text lines.
Methods
push()
push(line, contentWasTruncated?): void;
Append a line. When the buffer is full the oldest segment, and therefore the oldest lines, are dropped.
Set contentWasTruncated when the caller has replaced truncated content
with a line which fits, so TextRingBuffer.truncatedLines includes
it.
Parameters
| Parameter | Type |
|---|---|
line | string |
contentWasTruncated? | boolean |
Returns
void
size()
size(): number;
The number of lines currently held in memory.
Returns
number
byteLength()
byteLength(): number;
The number of bytes currently held in memory.
Returns
number
isEmpty()
isEmpty(): boolean;
Whether no line is currently held in memory.
Returns
boolean
droppedLines()
droppedLines(): number;
The number of lines dropped since creation, either because they were
evicted to make room, or because a segment was handed over to
onSegmentSealed.
Returns
number
truncatedLines()
truncatedLines(): number;
The number of lines whose content was truncated, either by the buffer to fit a segment or by the caller before appending a replacement.
Returns
number
clear()
clear(): void;
Drop every line and reset all counters.
Returns
void
flush()
flush(): void;
Seal the active segment, i.e. hand the most recent lines, which are not
full enough to be sealed on their own yet, to onSegmentSealed.
The segment is sealed for good, giving up its remaining capacity, so no line is ever reported twice. Flushing while the active segment holds no lines is a no-op, but flushing often means more, less full, segments and therefore fewer retained lines.
Returns
void
toBlobParts()
toBlobParts(): Uint8Array<ArrayBuffer>[];
The retained lines, oldest first, as byte views suitable for constructing
a Blob without decoding or copying.
The views point directly into the buffer's memory, which is recycled as
lines are evicted, so their content changes as more lines are pushed.
Consumers which need a stable copy must either copy each view, or hand
them to something which copies, e.g. the Blob constructor.
Returns
Uint8Array<ArrayBuffer>[]
toString()
toString(): string;
The retained lines, oldest first, decoded and concatenated.
Returns
string
toArray()
toArray(): string[];
The retained lines, oldest first, decoded into an array.
Returns
string[]
[iterator]()
iterator: IterableIterator<string>;
Iterates the retained lines, oldest first, decoding lazily.
Returns
IterableIterator<string>