UNPKG

streaming

Version:

Transforms and other streaming helpers

34 lines (33 loc) 1.07 kB
import { Script } from 'vm'; import { Transform } from 'stream'; export interface VMContext { $in?: any; $out?: any; } /** code: string Two important facts about this code: 1. It should process a global variable, `$in`, which represents the current object in the stream. 2. It should set the global variable `$out`, which represents the object that will be returned and sent downstream. context?: any = {} Results and side effects are tracked in this global context object. filename?: string = 'streaming.vm' Used in stack traces. */ export declare class VM<S, T> extends Transform { context: VMContext; filename: string; protected script: Script; constructor(code: string, context?: VMContext, filename?: string); /** each chunk should be a discrete object encoding should be null */ _transform(chunk: S, encoding: BufferEncoding, callback: (error?: Error, outputChunk?: T) => void): void; /** Run a bit of code once using the streaming.VM's global context. */ run(code: string): any; }