async read(buffer, offset, length) {
        if (length === 0) {
            return 0;
        }
        if (this.peekQueue.length === 0 && this.endOfStream) {
            throw new EndOfFileStream_1.EndOfStreamError();
        }
        let remaining = length;
        let bytesRead = 0;
        // consume peeked data first
        while (this.peekQueue.length > 0 && remaining > 0) {
            const peekData = this.peekQueue.pop(); // Front of queue
            if (!peekData)
                throw new Error('peekData should be defined');
            const lenCopy = Math.min(peekData.length, remaining);
            buffer.set(peekData.subarray(0, lenCopy), offset + bytesRead);
            bytesRead += lenCopy;
            remaining -= lenCopy;
            if (lenCopy < peekData.length) {
                // remainder back to queue
                this.peekQueue.push(peekData.subarray(lenCopy));
            }
        }
        // continue reading from stream if required
        while (remaining > 0 && !this.endOfStream) {
            const reqLen = Math.min(remaining, maxStreamReadSize);
            const chunkLen = await this.readFromStream(buffer, offset + bytesRead, reqLen);
            bytesRead += chunkLen;
            if (chunkLen < reqLen)
                break;
            remaining -= chunkLen;
        }
        return bytesRead;
    }
/**
     * Read chunk from stream
     * @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
     * @param offset - Offset target
     * @param length - Number of bytes to read
     * @returns Number of bytes read
     */
Read chunk from stream
@param buffer - Target Uint8Array (or Buffer) to store data read from stream in
@param offset - Offset target
@param length - Number of bytes to read
@returns Number of bytes read
Read chunk from stream @param buffer - Target Uint8Array ( or Buffer ) to store data read from stream in @param offset - Offset target @param length - Number of bytes to read @returns Number of bytes read
async read(buffer, offset, length) {
        if (length === 0) {
            return 0;
        }
        if (this.peekQueue.length === 0 && this.endOfStream) {
            throw new EndOfFileStream_1.EndOfStreamError();
        }
        let remaining = length;
        let bytesRead = 0;
        while (this.peekQueue.length > 0 && remaining > 0) {
            const peekData = this.peekQueue.pop(); 
            if (!peekData)
                throw new Error('peekData should be defined');
            const lenCopy = Math.min(peekData.length, remaining);
            buffer.set(peekData.subarray(0, lenCopy), offset + bytesRead);
            bytesRead += lenCopy;
            remaining -= lenCopy;
            if (lenCopy < peekData.length) {
                this.peekQueue.push(peekData.subarray(lenCopy));
            }
        }
        while (remaining > 0 && !this.endOfStream) {
            const reqLen = Math.min(remaining, maxStreamReadSize);
            const chunkLen = await this.readFromStream(buffer, offset + bytesRead, reqLen);
            bytesRead += chunkLen;
            if (chunkLen < reqLen)
                break;
            remaining -= chunkLen;
        }
        return bytesRead;
    }
async read ( buffer , offset , length ) { if ( length === 0 ) { return 0 ; } if ( this . peekQueue . length === 0 && this . endOfStream ) { throw new EndOfFileStream_1 . EndOfStreamError ( ) ; } let remaining = length ; let bytesRead = 0 ; while ( this . peekQueue . length > 0 && remaining > 0 ) { const peekData = this . peekQueue . pop ( ) ; if ( ! peekData ) throw new Error ( 'peekData should be defined' ) ; const lenCopy = Math . min ( peekData . length , remaining ) ; buffer . set ( peekData . subarray ( 0 , lenCopy ) , offset + bytesRead ) ; bytesRead += lenCopy ; remaining -= lenCopy ; if ( lenCopy < peekData . length ) { this . peekQueue . push ( peekData . subarray ( lenCopy ) ) ; } } while ( remaining > 0 && ! this . endOfStream ) { const reqLen = Math . min ( remaining , maxStreamReadSize ) ; const chunkLen = await this . readFromStream ( buffer , offset + bytesRead , reqLen ) ; bytesRead += chunkLen ; if ( chunkLen < reqLen ) break ; remaining -= chunkLen ; } return bytesRead ; }
Read chunk from stream
 @param buffer - Target Uint8Array (or Buffer) to store data read from stream in
 @param offset - Offset target
 @param length - Number of bytes to read
 @returns Number of bytes read
Read chunk from stream @param buffer - Target Uint8Array ( or Buffer ) to store data read from stream in @param offset - Offset target @param length - Number of bytes to read @returns Number of bytes read
// consume peeked data first
 // Front of queue
 // remainder back to queue
 // continue reading from stream if required
