export * from './fixed' ; /**
 * Stream instance holds specific input or output resource
 */ export interface Stream { /**
     * Indicate current stream is ended or not
     */ readonly ended : boolean ; /**
     * Close current stream
     */ close ( ) : void ; } /**
 * Readable stream.
 * Data can be read from stream.
 */ export interface ReadStream extends Stream { param buffer return read ( buffer ) : Promise < number | null > ; } /**
 * Additional Readstream util
 */ export namespace ReadStreamUtil { param { ReadStream } stream param { number } size return { AsyncIterableIterator < Uint8Array > } export function iter ( stream , size = 65535 ) { return { [ Symbol . asyncIterator ] ( ) { return this ; } , async next ( ) { const buffer = new Uint8Array ( size ) ; const read = await stream . read ( buffer ) ; if ( ! read ) return { done : true , value : null } ; return { done : false , value : buffer . subarray ( 0 , read ) } ; } } ; } param { ReadStream } stream export async function all ( stream ) { const bufferList = [ ] ; let total = 0 ; for await ( const buffer of iter ( stream ) ) { bufferList . push ( buffer ) ; total += buffer . byteLength ; } const data = new Uint8Array ( total ) ; let offset = 0 ; for ( const buffer of bufferList ) { data . set ( buffer , offset ) ; offset += buffer . byteLength ; } return data ; } param { ReadStream } stream param { number } size export async function exact ( stream , size ) { const data = new Uint8Array ( size ) ; let read = await stream . read ( data ) ; if ( ! read ) return null ; while ( read < size ) { const dataRead = await stream . read ( data . subarray ( read ) ) ; if ( ! dataRead ) return null ; read += dataRead ; } return data ; } param { ReadStream } read param { WriteStream } write return { Promise < number > } export async function copy ( read , write ) { let written = 0 ; for await ( const data of iter ( read ) ) { if ( write . ended ) break ; written += await write . write ( data ) ; } return written ; } } /**
 * Writable stream.
 * Data can be written to stream.
 */ export interface WriteStream extends Stream { param data return write ( data ) : Promise < number > ; } /**
 * Read / write stream
 */ export interface BiStream extends ReadStream , WriteStream { }