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

Function readAvailable

packages/platform/node-shared/src/NodeSocket.ts:43–56  ·  view source on GitHub ↗
(
  conn: Duplex,
  chunkSize: number
)

Source from the content-addressed store, hash-verified

41) {}
42
43const readAvailable = (
44 conn: Duplex,
45 chunkSize: number
46): Arr.NonEmptyReadonlyArray<Uint8Array | string> | undefined => {
47 const first = conn.read() as Uint8Array | string | null
48 if (first === null) return undefined
49 const out: [Uint8Array | string, ...Array<Uint8Array | string>] = [first]
50 let chunk: Uint8Array | string | null
51 // read() may synchronously refill the buffer; leave further reads to the next pull.
52 while (out.length < chunkSize && (chunk = conn.read() as Uint8Array | string | null) !== null) {
53 out.push(chunk)
54 }
55 return out
56}
57
58const toBuffers = (input: string | Uint8Array | ReadonlyArray<string | Uint8Array>): Array<Buffer> =>
59 Arr.map(Arr.ensure(input), (value) => Buffer.from(value))

Callers 1

drainFunction · 0.85

Calls 2

readMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected