import { Parser , Handler , ParserOptions } from "./Parser" ; import { Writable } from "stream" ; import { StringDecoder } from "string_decoder" ; function isBuffer ( _chunk , encoding ) { return encoding === "buffer" ; } see Parser export class WritableStream extends Writable { _parser : Parser ; _decoder = new StringDecoder ( ) ; constructor ( cbs , options ? ) { super ( { decodeStrings : false } ) ; this . _parser = new Parser ( cbs , options ) ; } _write ( chunk , encoding , cb ) { if ( isBuffer ( chunk , encoding ) ) chunk = this . _decoder . write ( chunk ) ; this . _parser . write ( chunk ) ; cb ( ) ; } _final ( cb ) { this . _parser . end ( this . _decoder . end ( ) ) ; cb ( ) ; } }