mirror of
https://github.com/n8n-io/n8n.git
synced 2026-06-01 09:17:08 +02:00
23 lines
660 B
TypeScript
23 lines
660 B
TypeScript
import { isObjectLiteral } from '@n8n/backend-common';
|
|
|
|
/** A nodejs Buffer gone through JSON.stringify */
|
|
export type SerializedBuffer = {
|
|
type: 'Buffer';
|
|
data: number[]; // Array like Uint8Array, each item is uint8 (0-255)
|
|
};
|
|
|
|
/** Converts the given SerializedBuffer to nodejs Buffer */
|
|
export function toBuffer(serializedBuffer: SerializedBuffer): Buffer {
|
|
return Buffer.from(serializedBuffer.data);
|
|
}
|
|
|
|
export function isSerializedBuffer(candidate: unknown): candidate is SerializedBuffer {
|
|
return (
|
|
isObjectLiteral(candidate) &&
|
|
'type' in candidate &&
|
|
'data' in candidate &&
|
|
candidate.type === 'Buffer' &&
|
|
Array.isArray(candidate.data)
|
|
);
|
|
}
|