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

Method readAlloc

packages/platform/node-shared/src/NodeFileSystem.ts:304–327  ·  view source on GitHub ↗
(size: FileSystem.SizeInput)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

someMethod · 0.80
NumberInterface · 0.50
BigIntInterface · 0.50
mapMethod · 0.45

Tested by

no test coverage detected