import { makeSourceEnvelope } from '@cucumber/gherkin' ; import { Transform , TransformCallback } from 'stream' ; import { relative } from 'path' ; /**
 * Stream that reads a string and writes a single Source message.
 */ export default class SourceMessageStream extends Transform { private buffer = Buffer . alloc ( 0 ) ; constructor ( private readonly uri , private readonly relativeTo ? ) { super ( { readableObjectMode : true , writableObjectMode : false } ) ; } public _transform ( chunk , encoding , callback ) { this . buffer = Buffer . concat ( [ this . buffer , chunk ] ) ; callback ( ) ; } public _flush ( callback ) { const data = this . buffer . toString ( 'utf-8' ) ; const chunk = makeSourceEnvelope ( data , this . relativeTo ? relative ( this . relativeTo , this . uri ) : this . uri ) ; this . push ( chunk ) ; callback ( ) ; } }