| 219 | * @since 4.0.0 |
| 220 | */ |
| 221 | export 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 |