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

Method readChunk

packages/platform/deno/src/DenoFileSystem.ts:234–267  ·  view source on GitHub ↗
(method: string, buffer: Uint8Array, explicit: bigint | undefined)

Source from the content-addressed store, hash-verified

232 }
233
234 private readChunk(method: string, buffer: Uint8Array, explicit: bigint | undefined) {
235 return Effect.suspend(() => {
236 if (explicit !== undefined && explicit < BigInt(0)) {
237 return Effect.fail(PlatformError.badArgument({
238 module: "FileSystem",
239 method,
240 description: "Cannot read before the start of the file"
241 }))
242 }
243 const position = explicit ?? this.position
244 return Effect.map(
245 tryPromise(
246 method,
247 undefined,
248 (signal) =>
249 this.native(signal, async () => {
250 if (this.nativePosition !== position) {
251 this.file.seekSync(position, Deno.SeekMode.Start)
252 }
253 this.nativePosition = undefined
254 const bytesRead = (await this.file.read(buffer)) ?? 0
255 this.nativePosition = position + BigInt(bytesRead)
256 return bytesRead
257 })
258 ),
259 (bytesRead) => {
260 if (explicit === undefined) {
261 this.position = position + BigInt(bytesRead)
262 }
263 return bytesRead
264 }
265 )
266 })
267 }
268
269 read(buffer: Uint8Array, options?: FileSystem.File.ReadOptions) {
270 return this.readChunk("read", buffer, options?.position)

Callers 2

readMethod · 0.95
readAllocMethod · 0.95

Calls 6

nativeMethod · 0.95
tryPromiseFunction · 0.70
failMethod · 0.65
readMethod · 0.65
BigIntInterface · 0.50
mapMethod · 0.45

Tested by

no test coverage detected