feat(streaming): Add streaming support: chunked stream transfers, file send/receive, stream events and helpers
This commit is contained in:
19
ts/index.ts
19
ts/index.ts
@@ -6,6 +6,7 @@ export * from './classes.ipcclient.js';
|
||||
import { IpcServer } from './classes.ipcserver.js';
|
||||
import { IpcClient } from './classes.ipcclient.js';
|
||||
import { IpcChannel } from './classes.ipcchannel.js';
|
||||
import { stream as nodeStream, fs as nodeFs, path as nodePath } from './smartipc.plugins.js';
|
||||
import type { IIpcServerOptions } from './classes.ipcserver.js';
|
||||
import type { IIpcClientOptions, IConnectRetryConfig } from './classes.ipcclient.js';
|
||||
import type { IIpcChannelOptions } from './classes.ipcchannel.js';
|
||||
@@ -129,3 +130,21 @@ export class SmartIpc {
|
||||
|
||||
// Export the main class as default
|
||||
export default SmartIpc;
|
||||
|
||||
/**
|
||||
* Helper: pipe an incoming SmartIPC readable stream to a file path.
|
||||
* Ensures directory exists; resolves on finish.
|
||||
*/
|
||||
export async function pipeStreamToFile(readable: NodeJS.ReadableStream, filePath: string): Promise<void> {
|
||||
// Ensure directory exists
|
||||
try {
|
||||
nodeFs.mkdirSync(nodePath.dirname(filePath), { recursive: true });
|
||||
} catch {}
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const ws = nodeFs.createWriteStream(filePath);
|
||||
ws.on('finish', () => resolve());
|
||||
ws.on('error', reject);
|
||||
readable.on('error', reject);
|
||||
(readable as any).pipe(ws);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user