* Implements the readable _read method. * @param {number} size Number of bytes to read
(size)
| 121 | * @param {number} size Number of bytes to read |
| 122 | */ |
| 123 | _read(size) { |
| 124 | if (this.destroyed || this.#fd === null) { |
| 125 | this.destroy(createEBADF('read')); |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | // Load content on first read (lazy loading) |
| 130 | if (this.#content === null) { |
| 131 | try { |
| 132 | const vfd = getVirtualFd(this.#fd); |
| 133 | if (!vfd) { |
| 134 | this.destroy(createEBADF('read')); |
| 135 | return; |
| 136 | } |
| 137 | // Use the file handle's readFileSync to get content |
| 138 | this.#content = vfd.entry.readFileSync(); |
| 139 | this.pending = false; |
| 140 | } catch (err) { |
| 141 | this.destroy(err); |
| 142 | return; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | // Calculate how much to read |
| 147 | // Note: end is inclusive, so we use end + 1 for the upper bound |
| 148 | const endPos = this.#end === Infinity ? this.#content.length : this.#end + 1; |
| 149 | const remaining = MathMin(endPos, this.#content.length) - this.#pos; |
| 150 | if (remaining <= 0) { |
| 151 | this.push(null); |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | const bytesToRead = MathMin(size, remaining); |
| 156 | const chunk = this.#content.subarray(this.#pos, this.#pos + bytesToRead); |
| 157 | this.#pos += bytesToRead; |
| 158 | this.bytesRead += bytesToRead; |
| 159 | |
| 160 | this.push(chunk); |
| 161 | |
| 162 | // Check if we've reached the end |
| 163 | if (this.#pos >= endPos || this.#pos >= this.#content.length) { |
| 164 | this.push(null); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Closes the file descriptor. |
nothing calls this directly
no test coverage detected