MCPcopy
hub / github.com/copy/v86 / write

Method write

src/browser/fake_network.js:89–120  ·  view source on GitHub ↗

* @param {Uint8Array} src_array

(src_array)

Source from the content-addressed store, hash-verified

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

Callers 15

IOAPICFunction · 0.80
virtio.jsFile · 0.80
fake_network.jsFile · 0.80
SerialAdapterXtermJSFunction · 0.80
init_uiFunction · 0.80
wisp_network.jsFile · 0.80
on_data_httpFunction · 0.80
pumpFunction · 0.80
virtio_console.jsFile · 0.80
fetch_network.jsFile · 0.80
linux-boot.jsFile · 0.80
snapshot.jsFile · 0.80

Calls 1

peekMethod · 0.95

Tested by

no test coverage detected