fix(core): Fix binary data helpers (like prepareBinaryData) with task runner (#12259)

This commit is contained in:
Tomi Turtiainen
2024-12-18 18:45:05 +02:00
committed by GitHub
parent 92af245d1a
commit 0f1461f2d5
13 changed files with 495 additions and 143 deletions

View File

@@ -0,0 +1,24 @@
/** 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);
}
function isObjectLiteral(item: unknown): item is { [key: string]: unknown } {
return typeof item === 'object' && item !== null && !Array.isArray(item);
}
export function isSerializedBuffer(candidate: unknown): candidate is SerializedBuffer {
return (
isObjectLiteral(candidate) &&
'type' in candidate &&
'data' in candidate &&
candidate.type === 'Buffer' &&
Array.isArray(candidate.data)
);
}

View File

@@ -24,3 +24,4 @@ export * from './ExecutionMetadata';
export * from './node-execution-context';
export * from './PartialExecutionUtils';
export { ErrorReporter } from './error-reporter';
export * from './SerializedBuffer';