(size: number, options?: FileSystem.File.ReadOptions)
| 422 | } |
| 423 | |
| 424 | readAlloc(size: number, options?: FileSystem.File.ReadOptions) { |
| 425 | return Effect.suspend(() => { |
| 426 | try { |
| 427 | if (!Number.isInteger(size) || size < 0) { |
| 428 | throw new RangeError("size must be a non-negative integer") |
| 429 | } |
| 430 | const explicit = options?.position |
| 431 | if (explicit !== undefined && explicit < BigInt(0)) { |
| 432 | return Effect.fail(negativePosition("readAlloc")) |
| 433 | } |
| 434 | const buffer = Buffer.allocUnsafeSlow(size) |
| 435 | const read = (position: bigint | null) => nodeReadAlloc(this.fd, { buffer, position }) |
| 436 | return Effect.map( |
| 437 | explicit === undefined ? this.atCursor(read) : read(explicit), |
| 438 | (bytesRead): Option.Option<Buffer> => { |
| 439 | if (bytesRead === 0) { |
| 440 | return Option.none() |
| 441 | } |
| 442 | if (bytesRead === size) { |
| 443 | return Option.some(buffer) |
| 444 | } |
| 445 | |
| 446 | const dst = Buffer.allocUnsafeSlow(bytesRead) |
| 447 | buffer.copy(dst, 0, 0, bytesRead) |
| 448 | return Option.some(dst) |
| 449 | } |
| 450 | ) |
| 451 | } catch (cause) { |
| 452 | return Effect.fail(handleBadArgument("readAlloc")(cause)) |
| 453 | } |
| 454 | }) |
| 455 | } |
| 456 | |
| 457 | truncate(length?: number) { |
| 458 | return Effect.map(nodeTruncate(this.fd, length || undefined), () => { |
nothing calls this directly
no test coverage detected