(count)
| 68 | this.#doRead = undefined; |
| 69 | } |
| 70 | read(count) { |
| 71 | const data = this.#data; |
| 72 | if (!data) |
| 73 | return; |
| 74 | |
| 75 | let result; |
| 76 | if (this.#format) { |
| 77 | if (undefined !== count) { |
| 78 | const available = data.byteLength - data.position; |
| 79 | if ("object" === typeof count) { |
| 80 | result = count.byteLength; |
| 81 | if (result > available) |
| 82 | result = available; |
| 83 | |
| 84 | const buffer = ArrayBuffer.isView(count) ? new Uint8Array(count.buffer, count.byteOffset, result) : new Uint8Array(count.buffer); |
| 85 | buffer.set(data.subarray(data.position, data.position + result)); |
| 86 | data.position += result; |
| 87 | } |
| 88 | else { |
| 89 | if (count > available) |
| 90 | throw new Error("invalid") |
| 91 | result = data.slice(data.position, data.position + count).buffer; |
| 92 | data.position += count; |
| 93 | } |
| 94 | if (data.position === data.byteLength) |
| 95 | this.#data = undefined; |
| 96 | } |
| 97 | else { // could optimize when entire buffer is requested |
| 98 | result = data.slice(data.position, data.position + data.byteLength).buffer; |
| 99 | this.#data = undefined; |
| 100 | } |
| 101 | } |
| 102 | else { |
| 103 | result = data[data.position++]; |
| 104 | if (data.position === data.byteLength) |
| 105 | this.#data = undefined; |
| 106 | } |
| 107 | |
| 108 | if (!this.#data && this.#socket.readable) { |
| 109 | this.#doRead ??= Timer.set(() => { |
| 110 | this.#doRead = undefined; |
| 111 | if (this.#socket.readable) |
| 112 | this.#onReadable(this.#socket.readable); |
| 113 | }); |
| 114 | } |
| 115 | |
| 116 | return result; |
| 117 | } |
| 118 | write(buffer, options) { |
| 119 | if (buffer instanceof DataView) |
| 120 | buffer = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength); |
nothing calls this directly
no test coverage detected