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

Function decodeString

packages/effect/src/encoding/Ndjson.ts:273–306  ·  view source on GitHub ↗
(options?: {
  readonly ignoreEmptyLines?: boolean | undefined
})

Source from the content-addressed store, hash-verified

271 * @since 4.0.0
272 */
273export const decodeString = <IE = never, Done = unknown>(options?: {
274 readonly ignoreEmptyLines?: boolean | undefined
275}): Channel.Channel<
276 Arr.NonEmptyReadonlyArray<unknown>,
277 IE | NdjsonError,
278 Done,
279 Arr.NonEmptyReadonlyArray<string>,
280 IE,
281 Done
282> =>
283 Channel.fromTransform((upstream, scope) => {
284 const ignoreEmptyLines = options?.ignoreEmptyLines === true
285 // splitLines only emits a line after its input has ended when that line
286 // has no terminator
287 let ended = false
288 const input = Pull.matchEffect(upstream, {
289 onSuccess: Effect.succeed,
290 onFailure: Effect.failCause,
291 onDone: (leftover) => {
292 ended = true
293 return Cause.done(leftover)
294 }
295 })
296 return Effect.map(
297 Channel.toTransform(Channel.splitLines<IE, Done>())(input, scope),
298 (lines) =>
299 makeDecodePull(lines, (chunk, out) => {
300 for (const line of chunk) {
301 const error = parseLine(line, out, ignoreEmptyLines, ended)
302 if (error !== undefined) return error
303 }
304 }, flushNothing)
305 )
306 })
307
308const LF = 0x0a
309const CR = 0x0d

Callers 2

decodeSchemaStringFunction · 0.70
Ndjson.tsFile · 0.70

Calls 4

makeDecodePullFunction · 0.85
parseLineFunction · 0.70
doneMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected