| 6895 | let done = Option.none<Done>() |
| 6896 | |
| 6897 | function splitLinesArray(chunk: Arr.NonEmptyReadonlyArray<string>): Arr.NonEmptyReadonlyArray<string> | null { |
| 6898 | const chunkBuilder: Array<string> = [] |
| 6899 | |
| 6900 | function pushLine(segment: string): void { |
| 6901 | if (stringBuilder.length === 0) { |
| 6902 | chunkBuilder.push(segment) |
| 6903 | } else { |
| 6904 | chunkBuilder.push(stringBuilder + segment) |
| 6905 | stringBuilder = "" |
| 6906 | } |
| 6907 | } |
| 6908 | |
| 6909 | for (let i = 0; i < chunk.length; i++) { |
| 6910 | const str = chunk[i] |
| 6911 | if (str.length !== 0) { |
| 6912 | let from = 0 |
| 6913 | let indexOfCR = str.indexOf("\r") |
| 6914 | let indexOfLF = str.indexOf("\n") |
| 6915 | if (midCRLF) { |
| 6916 | if (indexOfLF === 0) { |
| 6917 | from = 1 |
| 6918 | indexOfLF = str.indexOf("\n", from) |
| 6919 | } |
| 6920 | midCRLF = false |
| 6921 | } |
| 6922 | while (indexOfCR !== -1 || indexOfLF !== -1) { |
| 6923 | if (indexOfCR === -1 || (indexOfLF !== -1 && indexOfLF < indexOfCR)) { |
| 6924 | pushLine(str.substring(from, indexOfLF)) |
| 6925 | from = indexOfLF + 1 |
| 6926 | indexOfLF = str.indexOf("\n", from) |
| 6927 | } else { |
| 6928 | pushLine(str.substring(from, indexOfCR)) |
| 6929 | if (str.length === indexOfCR + 1) { |
| 6930 | midCRLF = true |
| 6931 | from = str.length |
| 6932 | indexOfCR = -1 |
| 6933 | } else { |
| 6934 | from = indexOfCR + (indexOfLF === indexOfCR + 1 ? 2 : 1) |
| 6935 | indexOfCR = str.indexOf("\r", from) |
| 6936 | indexOfLF = str.indexOf("\n", from) |
| 6937 | } |
| 6938 | } |
| 6939 | } |
| 6940 | stringBuilder = stringBuilder + str.substring(from) |
| 6941 | } |
| 6942 | } |
| 6943 | return Arr.isReadonlyArrayNonEmpty(chunkBuilder) ? chunkBuilder : null |
| 6944 | } |
| 6945 | |
| 6946 | const pullOrFlush: Pull.Pull<Arr.NonEmptyReadonlyArray<string>, Err, Done> = Effect.suspend(() => { |
| 6947 | if (done._tag === "Some") { |