mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
fix(core): Add a helper function to convert binary streams to buffers (no-changelog) (#5641)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
8
packages/core/src/BinaryDataManager/utils.ts
Normal file
8
packages/core/src/BinaryDataManager/utils.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import concatStream from 'concat-stream';
|
||||
import type { Readable } from 'stream';
|
||||
|
||||
export const binaryToBuffer = async (body: Buffer | Readable) =>
|
||||
new Promise<Buffer>((resolve) => {
|
||||
if (Buffer.isBuffer(body)) resolve(body);
|
||||
else body.pipe(concatStream(resolve));
|
||||
});
|
||||
@@ -149,7 +149,6 @@ const createFormDataObject = (data: Record<string, unknown>) => {
|
||||
});
|
||||
return formData;
|
||||
};
|
||||
|
||||
function searchForHeader(headers: IDataObject, headerName: string) {
|
||||
if (headers === undefined) {
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user