async searchForBlockIndexEntry(blockNumber, boundsMin, boundsMax) {

//        console.log(`${blockNumber}  ${boundsMin}  ${boundsMax}`)
        const chunkSize = 16 * 100000;
        if (boundsMax - boundsMin < chunkSize) {
            const data = await this.file.read(boundsMin, boundsMax - boundsMin);
            const dis = new BinaryParser(new DataView(data));
            const blockIndex = {};
            let ptr = boundsMin;
            let firstBlockNumber, lastBlockNumber;
            while (ptr < boundsMax) {
                const bn = dis.getInt();
                const filePosition = dis.getLong();
                const blockSizeInBytes = dis.getInt();
                blockIndex[bn] = {filePosition: filePosition, size: blockSizeInBytes};
                if(firstBlockNumber === undefined) firstBlockNumber = bn;
                lastBlockNumber = bn;
                ptr += 16;
            }
            this.mapFileBounds = {min: boundsMin, max: boundsMax};
            this.blockNumberRange = {first: firstBlockNumber, last: lastBlockNumber};
            this.blockIndexMap = blockIndex;
            return blockIndex[blockNumber];

        }
        // Midpoint in units of 16 byte chunks
        const nEntries = (boundsMax - boundsMin) / 16;
        const pos1 = boundsMin + Math.floor(nEntries / 2) * 16;
        const data = await this.file.read(pos1, 16);
        const dis = new BinaryParser(new DataView(data));
        const bn = dis.getInt();
        if (bn === blockNumber) {
            const filePosition = dis.getLong();
            const blockSizeInBytes = dis.getInt();
            return {filePosition: filePosition, size: blockSizeInBytes}   // Extraordinarily lucky
        } else if (blockNumber > bn) {
            const bie = await this.searchForBlockIndexEntry(blockNumber, pos1 + 16, boundsMax);
            return bie;
        } else {
            const bie = await this.searchForBlockIndexEntry(blockNumber, boundsMin, pos1);
            return bie;
        }
    }
// boundsMin is guaranteed to start at the beginning of an entry, boundsMax at the end
boundsMin is guaranteed to start at the beginning of an entry, boundsMax at the end
boundsMin is guaranteed to start at the beginning of an entry boundsMax at the end
async searchForBlockIndexEntry(blockNumber, boundsMin, boundsMax) {
        const chunkSize = 16 * 100000;
        if (boundsMax - boundsMin < chunkSize) {
            const data = await this.file.read(boundsMin, boundsMax - boundsMin);
            const dis = new BinaryParser(new DataView(data));
            const blockIndex = {};
            let ptr = boundsMin;
            let firstBlockNumber, lastBlockNumber;
            while (ptr < boundsMax) {
                const bn = dis.getInt();
                const filePosition = dis.getLong();
                const blockSizeInBytes = dis.getInt();
                blockIndex[bn] = {filePosition: filePosition, size: blockSizeInBytes};
                if(firstBlockNumber === undefined) firstBlockNumber = bn;
                lastBlockNumber = bn;
                ptr += 16;
            }
            this.mapFileBounds = {min: boundsMin, max: boundsMax};
            this.blockNumberRange = {first: firstBlockNumber, last: lastBlockNumber};
            this.blockIndexMap = blockIndex;
            return blockIndex[blockNumber];
        }
        const nEntries = (boundsMax - boundsMin) / 16;
        const pos1 = boundsMin + Math.floor(nEntries / 2) * 16;
        const data = await this.file.read(pos1, 16);
        const dis = new BinaryParser(new DataView(data));
        const bn = dis.getInt();
        if (bn === blockNumber) {
            const filePosition = dis.getLong();
            const blockSizeInBytes = dis.getInt();
            return {filePosition: filePosition, size: blockSizeInBytes}   
        } else if (blockNumber > bn) {
            const bie = await this.searchForBlockIndexEntry(blockNumber, pos1 + 16, boundsMax);
            return bie;
        } else {
            const bie = await this.searchForBlockIndexEntry(blockNumber, boundsMin, pos1);
            return bie;
        }
    }
async searchForBlockIndexEntry ( blockNumber , boundsMin , boundsMax ) { const chunkSize = 16 * 100000 ; if ( boundsMax - boundsMin < chunkSize ) { const data = await this . file . read ( boundsMin , boundsMax - boundsMin ) ; const dis = new BinaryParser ( new DataView ( data ) ) ; const blockIndex = { } ; let ptr = boundsMin ; let firstBlockNumber , lastBlockNumber ; while ( ptr < boundsMax ) { const bn = dis . getInt ( ) ; const filePosition = dis . getLong ( ) ; const blockSizeInBytes = dis . getInt ( ) ; blockIndex [ bn ] = { filePosition : filePosition , size : blockSizeInBytes } ; if ( firstBlockNumber === undefined ) firstBlockNumber = bn ; lastBlockNumber = bn ; ptr += 16 ; } this . mapFileBounds = { min : boundsMin , max : boundsMax } ; this . blockNumberRange = { first : firstBlockNumber , last : lastBlockNumber } ; this . blockIndexMap = blockIndex ; return blockIndex [ blockNumber ] ; } const nEntries = ( boundsMax - boundsMin ) / 16 ; const pos1 = boundsMin + Math . floor ( nEntries / 2 ) * 16 ; const data = await this . file . read ( pos1 , 16 ) ; const dis = new BinaryParser ( new DataView ( data ) ) ; const bn = dis . getInt ( ) ; if ( bn === blockNumber ) { const filePosition = dis . getLong ( ) ; const blockSizeInBytes = dis . getInt ( ) ; return { filePosition : filePosition , size : blockSizeInBytes } } else if ( blockNumber > bn ) { const bie = await this . searchForBlockIndexEntry ( blockNumber , pos1 + 16 , boundsMax ) ; return bie ; } else { const bie = await this . searchForBlockIndexEntry ( blockNumber , boundsMin , pos1 ) ; return bie ; } }
boundsMin is guaranteed to start at the beginning of an entry, boundsMax at the end
boundsMin is guaranteed to start at the beginning of an entry boundsMax at the end
//        console.log(`${blockNumber}  ${boundsMin}  ${boundsMax}`) // Midpoint in units of 16 byte chunks // Extraordinarily lucky