mirror of
https://github.com/n8n-io/n8n.git
synced 2026-10-22 04:21:32 +02:00
Some checks are pending
Build: Benchmark Image / build (push) Waiting to run
CI: Master (Build, Test, Lint) / Build for Github Cache (push) Waiting to run
CI: Master (Build, Test, Lint) / Unit tests (22.22.3) (push) Waiting to run
CI: Master (Build, Test, Lint) / Unit tests (24.15.0) (push) Waiting to run
CI: Master (Build, Test, Lint) / Lint (push) Waiting to run
CI: Master (Build, Test, Lint) / Performance (push) Waiting to run
CI: Master (Build, Test, Lint) / Notify Slack on failure (push) Blocked by required conditions
Util: Sync API Docs / sync-public-api (push) Waiting to run
20 lines
572 B
TypeScript
20 lines
572 B
TypeScript
const CHUNK_SIZE = 65_536; // 64 KB
|
|
|
|
/** Feeds a buffer to a consumer in fixed-size slices. */
|
|
export function feedInChunks(options: {
|
|
data: Buffer;
|
|
push: (slice: Uint8Array, isFinal: boolean) => void;
|
|
shouldStop: () => boolean;
|
|
}): void {
|
|
const { data, push, shouldStop } = options;
|
|
if (data.length === 0) {
|
|
if (!shouldStop()) push(data, true);
|
|
return;
|
|
}
|
|
|
|
for (let offset = 0; offset < data.length && !shouldStop(); offset += CHUNK_SIZE) {
|
|
const end = Math.min(offset + CHUNK_SIZE, data.length);
|
|
push(data.subarray(offset, end), end === data.length);
|
|
}
|
|
}
|