| 172 | * @since 4.0.0 |
| 173 | */ |
| 174 | export const decodeString = <IE = never, Done = unknown>(options?: { |
| 175 | readonly ignoreEmptyLines?: boolean | undefined |
| 176 | }): Channel.Channel< |
| 177 | Arr.NonEmptyReadonlyArray<unknown>, |
| 178 | IE | NdjsonError, |
| 179 | Done, |
| 180 | Arr.NonEmptyReadonlyArray<string>, |
| 181 | IE, |
| 182 | Done |
| 183 | > => { |
| 184 | const lines = Channel.splitLines<IE, Done>().pipe( |
| 185 | options?.ignoreEmptyLines === true ? |
| 186 | Channel.filterArray((line) => line.length > 0) : |
| 187 | identity |
| 188 | ) |
| 189 | return Channel.mapEffect(lines, (chunk) => { |
| 190 | try { |
| 191 | return Effect.succeed(Arr.map(chunk, (line) => JSON.parse(line))) |
| 192 | } catch (cause) { |
| 193 | return Effect.fail(new NdjsonError({ kind: "Unpack", cause })) |
| 194 | } |
| 195 | }) |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Creates a channel that decodes UTF-8 byte chunks and parses them as NDJSON. |