* Returns all buffered bytes in chronological order (oldest first). * The returned Buffer is a copy and safe to send over a WebSocket.
()
| 49 | * The returned Buffer is a copy and safe to send over a WebSocket. |
| 50 | */ |
| 51 | read(): Buffer { |
| 52 | if (this.stored === 0) return Buffer.alloc(0); |
| 53 | |
| 54 | if (this.stored < this.capacity) { |
| 55 | // Buffer hasn't wrapped yet — contiguous region starting at index 0 |
| 56 | return Buffer.from(this.buf.subarray(0, this.stored)); |
| 57 | } |
| 58 | |
| 59 | // Buffer is full and has wrapped — oldest data starts at writePos |
| 60 | const out = Buffer.allocUnsafe(this.capacity); |
| 61 | const tailLen = this.capacity - this.writePos; |
| 62 | this.buf.copy(out, 0, this.writePos); // tail (oldest) |
| 63 | this.buf.copy(out, tailLen, 0, this.writePos); // head (newest) |
| 64 | return out; |
| 65 | } |
| 66 | } |
nothing calls this directly
no outgoing calls
no test coverage detected