MCPcopy Create free account
hub / github.com/Effect-TS/effect / readAlloc

Method readAlloc

packages/platform/node-shared/src/NodeFileSystem.ts:424–455  ·  view source on GitHub ↗
(size: number, options?: FileSystem.File.ReadOptions)

Source from the content-addressed store, hash-verified

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), () => {

Callers

nothing calls this directly

Calls 8

atCursorMethod · 0.95
negativePositionFunction · 0.85
handleBadArgumentFunction · 0.85
someMethod · 0.80
failMethod · 0.65
BigIntInterface · 0.50
readFunction · 0.50
mapMethod · 0.45

Tested by

no test coverage detected