| 1066 | } |
| 1067 | } |
| 1068 | slice(start, end = this.#len) { |
| 1069 | if (end === start) { |
| 1070 | return new Uint8Array(); |
| 1071 | } |
| 1072 | checkRange(start, end, this.#len); |
| 1073 | const result = new Uint8Array(end - start); |
| 1074 | const startIdx = this.getChunkIndex(start); |
| 1075 | const endIdx = this.getChunkIndex(end - 1); |
| 1076 | let written = 0; |
| 1077 | for(let i = startIdx; i < endIdx; i++){ |
| 1078 | const chunk = this.#chunks[i]; |
| 1079 | const len = chunk.end - chunk.start; |
| 1080 | result.set(chunk.value.subarray(chunk.start, chunk.end), written); |
| 1081 | written += len; |
| 1082 | } |
| 1083 | const last = this.#chunks[endIdx]; |
| 1084 | const rest = end - start - written; |
| 1085 | result.set(last.value.subarray(last.start, last.start + rest), written); |
| 1086 | return result; |
| 1087 | } |
| 1088 | concat() { |
| 1089 | const result = new Uint8Array(this.#len); |
| 1090 | let sum = 0; |