(max: number)
| 1091 | } |
| 1092 | |
| 1093 | takeSome(max: number): Uint8Array { |
| 1094 | const chunk = this.chunks[this.head]! |
| 1095 | const available = chunk.length - this.offset |
| 1096 | if (max < available) { |
| 1097 | const out = chunk.subarray(this.offset, this.offset + max) |
| 1098 | this.offset += max |
| 1099 | this.length -= max |
| 1100 | this.consumed += max |
| 1101 | return out |
| 1102 | } |
| 1103 | const out = this.offset === 0 ? chunk : chunk.subarray(this.offset) |
| 1104 | this.chunks[this.head++] = undefined |
| 1105 | this.length -= available |
| 1106 | this.consumed += available |
| 1107 | this.offset = 0 |
| 1108 | if (this.head === this.chunks.length) { |
| 1109 | this.chunks = [] |
| 1110 | this.head = 0 |
| 1111 | } else if (this.head >= 1024) { |
| 1112 | this.chunks = this.chunks.slice(this.head) |
| 1113 | this.head = 0 |
| 1114 | } |
| 1115 | return out |
| 1116 | } |
| 1117 | |
| 1118 | // Takes exactly `n` bytes; the queue must hold at least `n` |
| 1119 | take(n: number): Uint8Array { |
no test coverage detected