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

Method readAlloc

packages/platform/deno/src/DenoFileSystem.ts:273–295  ·  view source on GitHub ↗
(size: number, options?: FileSystem.File.ReadOptions)

Source from the content-addressed store, hash-verified

271 }
272
273 readAlloc(size: number, options?: FileSystem.File.ReadOptions) {
274 return Effect.suspend(() => {
275 try {
276 if (!Number.isInteger(size) || size < 0) {
277 throw new RangeError("size must be a non-negative integer")
278 }
279 const buffer = new Uint8Array(size)
280 return Effect.map(this.readChunk("readAlloc", buffer, options?.position), (bytesRead) => {
281 if (bytesRead === 0) {
282 return Option.none()
283 }
284 return Option.some(bytesRead === size ? buffer : buffer.subarray(0, bytesRead))
285 })
286 } catch (cause) {
287 return Effect.fail(PlatformError.badArgument({
288 module: "FileSystem",
289 method: "readAlloc",
290 description: `Could not allocate a buffer of size ${size}`,
291 cause
292 }))
293 }
294 })
295 }
296
297 truncate(length?: number) {
298 const size = BigInt(length ?? 0)

Callers 3

testLayerFunction · 0.45
makeFunction · 0.45

Calls 4

readChunkMethod · 0.95
someMethod · 0.80
failMethod · 0.65
mapMethod · 0.45

Tested by

no test coverage detected