refactor(Read Binary File Node): Use node streams for to reduce memory usage (#5069)
This commit is contained in:
committed by
GitHub
parent
a455cce7e6
commit
8bee04cd2a
@@ -2,6 +2,7 @@ import fs from 'fs/promises';
|
||||
import { jsonParse } from 'n8n-workflow';
|
||||
import path from 'path';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import type { Readable } from 'stream';
|
||||
|
||||
import { BinaryMetadata, IBinaryDataConfig, IBinaryDataManager } from '../Interfaces';
|
||||
|
||||
@@ -66,10 +67,10 @@ export class BinaryDataFileSystem implements IBinaryDataManager {
|
||||
return jsonParse(await fs.readFile(this.getMetadataPath(identifier), { encoding: 'utf-8' }));
|
||||
}
|
||||
|
||||
async storeBinaryData(binaryBuffer: Buffer, executionId: string): Promise<string> {
|
||||
async storeBinaryData(binaryData: Buffer | Readable, executionId: string): Promise<string> {
|
||||
const binaryDataId = this.generateFileName(executionId);
|
||||
await this.addBinaryIdToPersistMeta(executionId, binaryDataId);
|
||||
await this.saveToLocalStorage(binaryBuffer, binaryDataId);
|
||||
await this.saveToLocalStorage(binaryData, binaryDataId);
|
||||
return binaryDataId;
|
||||
}
|
||||
|
||||
@@ -234,8 +235,8 @@ export class BinaryDataFileSystem implements IBinaryDataManager {
|
||||
await fs.cp(source, this.getBinaryPath(identifier));
|
||||
}
|
||||
|
||||
private async saveToLocalStorage(data: Buffer, identifier: string) {
|
||||
await fs.writeFile(this.getBinaryPath(identifier), data);
|
||||
private async saveToLocalStorage(binaryData: Buffer | Readable, identifier: string) {
|
||||
await fs.writeFile(this.getBinaryPath(identifier), binaryData);
|
||||
}
|
||||
|
||||
private async retrieveFromLocalStorage(identifier: string): Promise<Buffer> {
|
||||
|
||||
Reference in New Issue
Block a user