fix(core): Add a helper function to convert binary streams to buffers (no-changelog) (#5641)

This commit is contained in:
agobrech
2023-03-08 14:32:27 +01:00
committed by GitHub
parent c81656d149
commit 0d49ad8b93
3 changed files with 10 additions and 7 deletions

View File

@@ -1,4 +1,3 @@
import concatStream from 'concat-stream';
import { readFile, stat } from 'fs/promises';
import type { BinaryMetadata, IBinaryData, INodeExecutionData } from 'n8n-workflow';
import prettyBytes from 'pretty-bytes';
@@ -6,6 +5,7 @@ import type { Readable } from 'stream';
import { BINARY_ENCODING } from '../Constants';
import type { IBinaryDataConfig, IBinaryDataManager } from '../Interfaces';
import { BinaryDataFileSystem } from './FileSystem';
import { binaryToBuffer } from './utils';
export class BinaryDataManager {
static instance: BinaryDataManager | undefined;
@@ -104,11 +104,7 @@ export class BinaryDataManager {
fileSize,
});
} else {
// Else fallback to storing this data in memory.
const buffer = await new Promise<Buffer>((resolve) => {
if (Buffer.isBuffer(input)) resolve(input);
else input.pipe(concatStream(resolve));
});
const buffer = await binaryToBuffer(input);
binaryData.data = buffer.toString(BINARY_ENCODING);
binaryData.fileSize = prettyBytes(buffer.length);
}