import { PassThrough , Transform , TransformOptions } from 'stream' ; export interface IReadTarball { abort ? : ( ) => void ; } export interface IUploadTarball { done ? : ( ) => void ; abort ? : ( ) => void ; } param { * } options return { Stream } class ReadTarball extends PassThrough implements IReadTarball { param { Object } options public constructor ( options ) { super ( options ) ; addAbstractMethods ( this , 'abort' ) ; } public abort ( ) { } } param { * } options return { Stream } class UploadTarball extends PassThrough implements IUploadTarball { param { Object } options public constructor ( options ) { super ( options ) ; addAbstractMethods ( this , 'abort' ) ; addAbstractMethods ( this , 'done' ) ; } public abort ( ) { } public done ( ) { } } param { * } self param { * } name function addAbstractMethods ( self , name ) { self . _called_methods = self . _called_methods || { } ; self . __defineGetter__ ( name , function ( ) { return function ( ) : void { self . _called_methods [ name ] = true ; } ; } ) ; self . __defineSetter__ ( name , function ( fn ) { delete self [ name ] ; self [ name ] = fn ; if ( self . _called_methods && self . _called_methods [ name ] ) { delete self . _called_methods [ name ] ; self [ name ] ( ) ; } } ) ; } /**
 * Converts a buffer stream to a string.
 */ const readableToString = async ( stream ) => { const chunks = [ ] ; for await ( let chunk of stream ) { chunks . push ( Buffer . from ( chunk ) ) ; } const buffer = Buffer . concat ( chunks ) ; const str = buffer . toString ( 'utf-8' ) ; return str ; } ; /**
 * Transform stream object  mode to string
 **/ const transformObjectToString = ( ) => { return new Transform ( { objectMode : true , transform : ( chunk , encoding , callback ) => { callback ( null , JSON . stringify ( chunk ) ) ; } , } ) ; } ; export { ReadTarball , UploadTarball , readableToString , transformObjectToString } ;