This commit is contained in:
1 parent
63abaa819c
commit
63296e7ad3
7 files changed
+226
-19
No files matched your search
+4
-4
@@ -30,7 +30,7 @@
|
||||
return { hoster, fileName, ts, confirmed };
|
||||
}
|
||||
|
||||
async function* iterateBoundedUploadLogLines(chunks, maxLineLength) {
|
||||
async function* iterateBoundedUploadLogLines(chunks, maxLineLength, requireCompleteLines) {
|
||||
let buffer = '';
|
||||
for await (const chunk of chunks) {
|
||||
buffer += String(chunk);
|
||||
@@ -44,7 +44,7 @@
|
||||
}
|
||||
if (buffer.length > maxLineLength) throw new Error('Upload-Log-Zeile ist zu lang');
|
||||
}
|
||||
if (buffer) yield buffer.replace(/\r$/, '');
|
||||
if (buffer && !requireCompleteLines) yield buffer.replace(/\r$/, '');
|
||||
}
|
||||
|
||||
async function* iterateBoundedUploadLogChunks(chunks, maxBytes, onBytes) {
|
||||
@@ -67,13 +67,13 @@
|
||||
const maxBytes = Number.isFinite(Number(options.maxBytes)) ? Math.max(1, Math.floor(Number(options.maxBytes))) : 256 * 1024 * 1024;
|
||||
const yieldFn = typeof options.yieldFn === 'function' ? options.yieldFn : (() => new Promise(resolve => setImmediate(resolve)));
|
||||
const input = options.lines ? null : fsImpl.createReadStream(filePath, { encoding: 'utf8', highWaterMark: 32768 });
|
||||
const lines = options.lines || iterateBoundedUploadLogLines(iterateBoundedUploadLogChunks(input, maxBytes, options.onBytes), maxLineLength);
|
||||
const lines = options.lines || iterateBoundedUploadLogLines(iterateBoundedUploadLogChunks(input, maxBytes, options.onBytes), maxLineLength, options.requireCompleteLines);
|
||||
let count = 0;
|
||||
try {
|
||||
for await (const line of lines) {
|
||||
if (String(line).length > maxLineLength) throw new Error('Upload-Log-Zeile ist zu lang');
|
||||
const parsed = parseUploadLogLine(line);
|
||||
if (parsed) yield parsed;
|
||||
if (parsed) yield options.includeLine ? { ...parsed, line: String(line) } : parsed;
|
||||
count++;
|
||||
if (count % yieldEvery === 0) await yieldFn();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user