@strapi/data-transfer
Version:
Data transfer capabilities for Strapi
61 lines • 2.78 kB
TypeScript
/**
* Canonical **outbound** asset chunk for WebSocket JSON (push and pull).
* Base64 string `data` keeps `JSON.parse` heap bounded vs `{ type: 'Buffer', data: [n,…] }`.
*/
export declare function createTransferAssetStreamChunk(assetID: string, chunk: Buffer | Uint8Array): {
action: 'stream';
assetID: string;
encoding: 'base64';
data: string;
};
/**
* Legacy asset-chunk shape for remotes that pre-date #23479 and do `Buffer.from(item.data.data)`
* in their push handler. Used only when init negotiation indicates the remote does not understand
* {@link createTransferAssetStreamChunk}'s `encoding: 'base64'` field (the base64 string on `data`
* would leave `item.data.data` undefined and crash those remotes with `Buffer.from(undefined)`).
*
* `buffer.toJSON()` returns `{ type: 'Buffer', data: number[] }` — a plain object the WebSocket
* replacer passes through untouched, so the receiver sees the same shape the old default
* `JSON.stringify(Buffer)` used to produce.
*
* Note: this shape is ~6× larger on the wire than base64 and allocates the full byte array during
* `JSON.parse`, which is what #23479 was fixing for large files. Only use this when negotiation
* proves the remote cannot decode base64.
*/
export declare function createTransferAssetStreamChunkLegacy(assetID: string, chunk: Buffer | Uint8Array): {
action: 'stream';
assetID: string;
data: {
type: 'Buffer';
data: number[];
};
};
/**
* Decode a stream item from `TransferAssetFlow` after `JSON.parse` (shared by push + pull handlers
* and the remote source provider).
*/
export declare function decodeTransferAssetStreamItem(item: {
action: 'stream';
data: unknown;
encoding?: 'base64';
}): Buffer;
/**
* Decode binary payload for `TransferAssetFlow` `action: 'stream'` after JSON.parse.
*
* Supported shapes (receivers should accept all of these):
* - **String `data`:** preferred wire form (`createTransferAssetStreamChunk` / `encoding: 'base64'`).
* - **`{ type: 'Buffer', data: number[] | TypedArray }`:** legacy `Buffer.toJSON()` from default
* `JSON.stringify` (older clients/servers).
* - **`Buffer` instance:** in-process only.
*
* Note: Node’s `JSON.stringify` runs `Buffer.toJSON()` before any replacer, so nested `Buffer`
* values become the legacy object unless you pass a string (use `createTransferAssetStreamChunk`).
*/
export declare function decodeTransferAssetStreamData(data: unknown, encoding?: 'base64'): Buffer;
/** Approximate decoded byte size for batching (pull asset generator). */
export declare function transferAssetStreamChunkByteLength(chunk: {
action: string;
data?: unknown;
encoding?: 'base64';
}): number;
//# sourceMappingURL=transfer-asset-chunk.d.ts.map