diff --git a/src/helper/stream.ts b/src/helper/stream.ts index 297e20c..4102cf4 100644 --- a/src/helper/stream.ts +++ b/src/helper/stream.ts @@ -1,2 +1,33 @@ +/** + * Minimal writable stream interface for browser compatibility. + * + * This abstracts over Node.js streams and browser console output, + * providing a common write target for handlers. + */ +export interface Writable { + write(data: string): void; +} -export type MillisecondsSinceUnixEpoch = number; +/** + * A Writable backed by console.log. + */ +export class ConsoleWritable implements Writable { + write(data: string): void { + console.log(data); + } +} + +/** + * A Writable backed by console.error (stderr equivalent). + */ +export class StderrWritable implements Writable { + write(data: string): void { + console.error(data); + } +} + +/** + * Default output stream. Uses console.error to match Python's default + * of writing to sys.stderr. + */ +export const DEFAULT_STREAM: Writable = new StderrWritable();