mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 19:11:13 +00:00
fix(Google Drive Node): Fix file upload for streams (#11698)
This commit is contained in:
@@ -131,3 +131,29 @@ export function setParentFolder(
|
||||
return 'root';
|
||||
}
|
||||
}
|
||||
|
||||
export async function processInChunks(
|
||||
stream: Readable,
|
||||
chunkSize: number,
|
||||
process: (chunk: Buffer, offset: number) => void | Promise<void>,
|
||||
) {
|
||||
let buffer = Buffer.alloc(0);
|
||||
let offset = 0;
|
||||
|
||||
for await (const chunk of stream) {
|
||||
buffer = Buffer.concat([buffer, chunk]);
|
||||
|
||||
while (buffer.length >= chunkSize) {
|
||||
const chunkToProcess = buffer.subarray(0, chunkSize);
|
||||
await process(chunkToProcess, offset);
|
||||
|
||||
buffer = buffer.subarray(chunkSize);
|
||||
offset += chunkSize;
|
||||
}
|
||||
}
|
||||
|
||||
// Process last chunk, could be smaller than chunkSize
|
||||
if (buffer.length > 0) {
|
||||
await process(buffer, offset);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user