mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Perf: read most of files in one pass
This commit is contained in:
@@ -3,6 +3,7 @@ import { fetchWithRetry, defaultRequestInit } from './fetch-retry';
|
||||
|
||||
import { TextLineStream } from './text-line-transform-stream';
|
||||
import { PolyfillTextDecoderStream } from './text-decoder-stream';
|
||||
import { processLine } from './process-line';
|
||||
// function createTextLineStreamFromStreamSource(stream: ReadableStream<Uint8Array>) {
|
||||
// return stream
|
||||
// .pipeThrough(new PolyfillTextDecoderStream())
|
||||
@@ -54,3 +55,14 @@ export function createReadlineInterfaceFromResponse(this: void, resp: Response)
|
||||
export function fetchRemoteTextByLine(url: string | URL) {
|
||||
return fetchWithRetry(url, defaultRequestInit).then(createReadlineInterfaceFromResponse);
|
||||
}
|
||||
|
||||
export async function readFileIntoProcessedArray(file: string | URL | BunFile) {
|
||||
if (typeof file === 'string') {
|
||||
file = Bun.file(file);
|
||||
} else if (!('writer' in file)) {
|
||||
file = Bun.file(file);
|
||||
}
|
||||
|
||||
const content = await file.text();
|
||||
return content.split('\n').filter(processLine);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user