| 102 | * @since 4.0.0 |
| 103 | */ |
| 104 | export const encodeString = <IE = never, Done = unknown>(): Channel.Channel< |
| 105 | Arr.NonEmptyReadonlyArray<string>, |
| 106 | IE | NdjsonError, |
| 107 | Done, |
| 108 | Arr.NonEmptyReadonlyArray<unknown>, |
| 109 | IE, |
| 110 | Done |
| 111 | > => |
| 112 | Channel.fromTransform((upstream, _scope) => |
| 113 | Effect.succeed(Effect.flatMap(upstream, (input) => { |
| 114 | try { |
| 115 | return Effect.succeed(Arr.of( |
| 116 | input.map((item) => { |
| 117 | const output = JSON.stringify(item) |
| 118 | if (output === undefined) { |
| 119 | throw new TypeError("Value cannot be represented as JSON") |
| 120 | } |
| 121 | return output |
| 122 | }).join("\n") + "\n" |
| 123 | )) |
| 124 | } catch (cause) { |
| 125 | return Effect.fail(new NdjsonError({ kind: "Pack", cause })) |
| 126 | } |
| 127 | })) |
| 128 | ) |
| 129 | |
| 130 | /** |
| 131 | * Creates a channel that encodes chunks of values as UTF-8 NDJSON bytes. |