@@ -3,7 +3,7 @@ import { Readable } from 'node:stream';
3
3
import type { FileHandle } from 'node:fs/promises' ;
4
4
import readline from 'node:readline' ;
5
5
6
- import { TextLineStream } from './text-line-transform-stream' ;
6
+ import { ProcessLineStream , TextLineStream } from './text-line-transform-stream' ;
7
7
import type { ReadableStream } from 'node:stream/web' ;
8
8
import { TextDecoderStream } from 'node:stream/web' ;
9
9
import { processLine } from './process-line' ;
@@ -40,7 +40,7 @@ function ensureResponseBody<T extends NodeFetchResponse | UndiciResponseData | U
40
40
return resp . body ;
41
41
}
42
42
43
- export const createReadlineInterfaceFromResponse : ( ( resp : NodeFetchResponse | UndiciResponseData | UnidiciWebResponse ) => AsyncIterable < string > ) = ( resp ) => {
43
+ export const createReadlineInterfaceFromResponse : ( ( resp : NodeFetchResponse | UndiciResponseData | UnidiciWebResponse , processLine ?: boolean ) => ReadableStream < string > ) = ( resp , processLine = false ) => {
44
44
const stream = ensureResponseBody ( resp ) ;
45
45
46
46
const webStream : ReadableStream < Uint8Array > = 'getReader' in stream
@@ -51,13 +51,18 @@ export const createReadlineInterfaceFromResponse: ((resp: NodeFetchResponse | Un
51
51
: Readable . toWeb ( new Readable ( ) . wrap ( stream ) )
52
52
) ;
53
53
54
- return webStream
54
+ const resultStream = webStream
55
55
. pipeThrough ( new TextDecoderStream ( ) )
56
56
. pipeThrough ( new TextLineStream ( ) ) ;
57
+
58
+ if ( processLine ) {
59
+ return resultStream . pipeThrough ( new ProcessLineStream ( ) ) ;
60
+ }
61
+ return resultStream ;
57
62
} ;
58
63
59
- export function fetchRemoteTextByLine ( url : string ) {
60
- return $fetch ( url ) . then ( createReadlineInterfaceFromResponse ) ;
64
+ export function fetchRemoteTextByLine ( url : string , processLine = false ) : Promise < AsyncIterable < string > > {
65
+ return $fetch ( url ) . then ( resp => createReadlineInterfaceFromResponse ( resp , processLine ) ) ;
61
66
}
62
67
63
68
export async function readFileIntoProcessedArray ( file : string /* | FileHandle */ ) {
0 commit comments