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

Function readerBytes

packages/effect/src/socket/Socket.ts:221–241  ·  view source on GitHub ↗
(
  self: Socket
)

Source from the content-addressed store, hash-verified

219 * @since 4.0.0
220 */
221export const readerBytes = (
222 self: Socket
223): Effect.Effect<
224 Effect.Effect<NonEmptyReadonlyArray<Uint8Array>, SocketError>,
225 SocketError,
226 Scope.Scope
227> =>
228 Effect.map(self.reader, ({ pull }) =>
229 Effect.map(pull, (chunk) => {
230 for (let i = 0; i < chunk.length; i++) {
231 if (typeof chunk[i] === "string") {
232 const out = new Array<Uint8Array>(chunk.length) as NonEmptyArray<Uint8Array>
233 for (let j = 0; j < chunk.length; j++) {
234 const item = chunk[j]
235 out[j] = typeof item === "string" ? encoder.encode(item) : item
236 }
237 return out
238 }
239 }
240 return chunk as NonEmptyReadonlyArray<Uint8Array>
241 }))
242
243/**
244 * Acquires the socket's string `pull`, decoding binary frames with the optional

Callers 2

toChannelFunction · 0.85
toStreamFunction · 0.85

Calls 2

encodeMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected