* @param {Uint8Array} src_array
(src_array)
| 87 | * @param {Uint8Array} src_array |
| 88 | */ |
| 89 | write(src_array) |
| 90 | { |
| 91 | const src_length = src_array.length; |
| 92 | const total_length = this.length + src_length; |
| 93 | let capacity = this.buffer.length; |
| 94 | if(capacity < total_length) { |
| 95 | while(capacity < total_length) { |
| 96 | capacity *= 2; |
| 97 | } |
| 98 | if(this.maximum_capacity && capacity > this.maximum_capacity) { |
| 99 | throw new Error("stream capacity overflow in GrowableRingbuffer.write(), package dropped"); |
| 100 | } |
| 101 | const new_buffer = new Uint8Array(capacity); |
| 102 | this.peek(new_buffer); |
| 103 | this.tail = 0; |
| 104 | this.head = this.length; |
| 105 | this.buffer = new_buffer; |
| 106 | } |
| 107 | const buffer = this.buffer; |
| 108 | |
| 109 | const new_head = this.head + src_length; |
| 110 | if(new_head > capacity) { |
| 111 | const i_split = capacity - this.head; |
| 112 | buffer.set(src_array.subarray(0, i_split), this.head); |
| 113 | buffer.set(src_array.subarray(i_split)); |
| 114 | } |
| 115 | else { |
| 116 | buffer.set(src_array, this.head); |
| 117 | } |
| 118 | this.head = new_head % capacity; |
| 119 | this.length += src_length; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * @param {Uint8Array} dst_array |
no test coverage detected