| 302 | } |
| 303 | |
| 304 | readAlloc(size: FileSystem.SizeInput) { |
| 305 | const sizeNumber = Number(size) |
| 306 | return Effect.suspend(() => { |
| 307 | const buffer = Buffer.allocUnsafeSlow(sizeNumber) |
| 308 | const position = this.position |
| 309 | return Effect.map( |
| 310 | nodeReadAlloc(this.fd, { buffer, position }), |
| 311 | (bytesRead): Option.Option<Buffer> => { |
| 312 | if (bytesRead === 0) { |
| 313 | return Option.none() |
| 314 | } |
| 315 | |
| 316 | this.position = position + BigInt(bytesRead) |
| 317 | if (bytesRead === sizeNumber) { |
| 318 | return Option.some(buffer) |
| 319 | } |
| 320 | |
| 321 | const dst = Buffer.allocUnsafeSlow(bytesRead) |
| 322 | buffer.copy(dst, 0, 0, bytesRead) |
| 323 | return Option.some(dst) |
| 324 | } |
| 325 | ) |
| 326 | }) |
| 327 | } |
| 328 | |
| 329 | truncate(length?: FileSystem.SizeInput) { |
| 330 | return Effect.map(nodeTruncate(this.fd, length ? Number(length) : undefined), () => { |