MCPcopy Index your code
hub / github.com/Effect-TS/effect / readChunkStreamByobReader

Function readChunkStreamByobReader

packages/effect/src/internal/stream.ts:3328–3353  ·  view source on GitHub ↗
(
  reader: ReadableStreamBYOBReader,
  onError: (error: unknown) => E,
  size: number
)

Source from the content-addressed store, hash-verified

3326const EOF = Symbol.for("effect/Stream/EOF")
3327
3328const readChunkStreamByobReader = <E>(
3329 reader: ReadableStreamBYOBReader,
3330 onError: (error: unknown) => E,
3331 size: number
3332): Stream.Stream<Uint8Array, E | typeof EOF> => {
3333 const buffer = new ArrayBuffer(size)
3334 return paginateEffect(0, (offset) =>
3335 Effect.flatMap(
3336 Effect.tryPromise({
3337 try: () => reader.read(new Uint8Array(buffer, offset, buffer.byteLength - offset)),
3338 catch: (reason) => onError(reason)
3339 }),
3340 ({ done, value }) => {
3341 if (done) {
3342 return Effect.fail(EOF)
3343 }
3344 const newOffset = offset + value.byteLength
3345 return Effect.succeed([
3346 value,
3347 newOffset >= buffer.byteLength
3348 ? Option.none<number>()
3349 : Option.some(newOffset)
3350 ])
3351 }
3352 ))
3353}
3354
3355/** @internal */
3356export const groupAdjacentBy = dual<

Callers 1

fromReadableStreamByobFunction · 0.85

Calls 4

paginateEffectFunction · 0.85
readMethod · 0.80
failMethod · 0.65
onErrorFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…