diff --git a/Build/download-mock-assets.ts b/Build/download-mock-assets.ts index 6a9e3458..97b0901c 100644 --- a/Build/download-mock-assets.ts +++ b/Build/download-mock-assets.ts @@ -19,13 +19,12 @@ export const downloadMockAssets = task(require.main === module, __filename)((spa ([filename, url]) => span .traceChildAsync(url, async () => { const res = await fetchWithRetry(url); - - const src = path.join(OUTPUT_MOCK_DIR, filename); if (!res.body) { throw new Error(`Empty body from ${url}`); } await mkdirp(OUTPUT_MOCK_DIR); + const src = path.join(OUTPUT_MOCK_DIR, filename); return pipeline( Readable.fromWeb(res.body), diff --git a/Build/lib/fetch-text-by-line.ts b/Build/lib/fetch-text-by-line.ts index e1e6b0e2..7c916a45 100644 --- a/Build/lib/fetch-text-by-line.ts +++ b/Build/lib/fetch-text-by-line.ts @@ -10,6 +10,7 @@ import { processLine } from './process-line'; const getReadableStream = (file: string | FileHandle): ReadableStream => { if (typeof file === 'string') { + // return fs.openAsBlob(file).then(blob => blob.stream()) return Readable.toWeb(fs.createReadStream(file/* , { encoding: 'utf-8' } */)); } return file.readableWebStream(); diff --git a/Build/lib/text-line-transform-stream.ts b/Build/lib/text-line-transform-stream.ts index 82f5457e..618aabe1 100644 --- a/Build/lib/text-line-transform-stream.ts +++ b/Build/lib/text-line-transform-stream.ts @@ -25,23 +25,25 @@ export class TextLineStream extends TransformStream { allowCR = false }: TextLineStreamOptions = {}) { let __buf = ''; + let chunkIndex = 0; super({ transform(chunk, controller) { chunk = __buf + chunk; + chunkIndex = 0; for (; ;) { - const lfIndex = chunk.indexOf('\n'); + const lfIndex = chunk.indexOf('\n', chunkIndex); if (allowCR) { - const crIndex = chunk.indexOf('\r'); + const crIndex = chunk.indexOf('\r', chunkIndex); if ( crIndex !== -1 && crIndex !== (chunk.length - 1) && (lfIndex === -1 || (lfIndex - 1) > crIndex) ) { - controller.enqueue(chunk.slice(0, crIndex)); - chunk = chunk.slice(crIndex + 1); + controller.enqueue(chunk.slice(chunkIndex, crIndex)); + chunkIndex = crIndex + 1; continue; } } @@ -51,15 +53,15 @@ export class TextLineStream extends TransformStream { if (chunk[lfIndex - 1] === '\r') { crOrLfIndex--; } - controller.enqueue(chunk.slice(0, crOrLfIndex)); - chunk = chunk.slice(lfIndex + 1); + controller.enqueue(chunk.slice(chunkIndex, crOrLfIndex)); + chunkIndex = lfIndex + 1; continue; } break; } - __buf = chunk; + __buf = chunk.slice(chunkIndex); }, flush(controller) { if (__buf.length > 0) {