start by reading the end of the last block. this must always be kept in memory.
4070
function readInteger(width, reader) {
    return function (start, cb) {
      var i = Math.floor(start/block_size)
      var _i = start%block_size

      //if the UInt32BE aligns with in a block
      //read directly and it's 3x faster.
      if(_i < block_size - width)
        get(i, function (err, block) {
          if(err) return cb(err)
          var value = reader(block, start%block_size)
          cb(null, value)
        })
      //but handle overlapping reads this easier way
      //instead of messing around with bitwise ops
      else
        read(start, start+width, function (err, buf, bytes_read) {
          if(err) return cb(err)
          var value = reader(buf, 0);
          cb(isNaN(value) ? new Error('Number is too large') : null, value)
        })
    }
  }
727053
def _find_block_end(self, table, used_cells, block_start, block_end, start_pos, end_pos):
        '''
        
        '''
        table_row = table[block_start[0]]
        used_row = used_cells[block_start[0]]
        table_transpose = TableTranspose(table)

        # Find which column the titles end on
        for column_index in range(block_start[1], end_pos[1] + 1):
            # Ensure we catch the edge case of the data reaching the edge of the table -- block_end
            # should then equal end_pos
            block_end[1] = max(block_end[1], column_index)
            if column_index == end_pos[1]:
                break
            if used_row[column_index]:
                break
            elif is_empty_cell(table_row[column_index]):
                table_column = table_transpose[column_index]
                found_cell = False
                for row_index in range(block_start[0], block_end[0]):
                    if not is_empty_cell(table_column[row_index]):
                        found_cell = True
                        break
                # If we have a column of blanks, stop
                if not found_cell:
                    break
        return block_start, block_end
1118791
public final void mEND() throws RecognitionException {
		try {
			int _type = END;
			int _channel = DEFAULT_TOKEN_CHANNEL;
			// hql.g:24:5: ( 'end' )
			// hql.g:24:7: 'end'
			{
			match("end"); if (state.failed) return;

			}

			state.type = _type;
			state.channel = _channel;
		}
		finally {
			// do for sure before leaving
		}
	}
469702
public void endRead() {
		SynchronizationPoint<NoException> sp;
		synchronized (this) {
			// if others are still reading, nothing to do
			if (--readers > 0) return;
			// if nobody is waiting to write, nothing to do
			if (writersWaiting == null) return;
			sp = writersWaiting.removeFirst();
			if (writersWaiting.isEmpty()) writersWaiting = null;
			writer = true;
		}
		sp.unblock();
	}
930531
function(input, startIndex) {
		var begin;
		var end = startIndex;

		//First find the curly bracket that opens this block.
		while(end-- && input.charAt(end) !== '{') {}

		//The end is now fixed to the right of the selector.
		//Now start there to find the begin of the selector.
		begin = end;

		//Now walk farther backwards until we grabbed the whole selector.
		//This either ends at beginning of string or at end of next block.
		while(begin-- && input.charAt(begin - 1) !== '}') {}

		//Return the cleaned selector.
		return input.substring(begin, end).replace(/[\n\r\t]/g, '');
	}
184318
public synchronized void endInit() {
		if (win == null) return;
		progressText.setText("Starting framework...");
		progressBar.setMinimum(0);
		progressBar.setMaximum(10050);
		progressBar.setValue(50);
		bottom.invalidate();
	}
627070
private void initializeForRead(long rangeBeginning, long rangeEnd) throws IOException {
        // To get to the left-most byte desired by a user, we must skip over the 16 bytes of the
        // preliminary cipher block, and then possibly skip a few more bytes into the next block
        // to where the the left-most byte is located.
        int numBytesToSkip;
        if(rangeBeginning < JceEncryptionConstants.SYMMETRIC_CIPHER_BLOCK_SIZE) {
            numBytesToSkip = (int)rangeBeginning;
        } else {
            int offsetIntoBlock = (int)(rangeBeginning % JceEncryptionConstants.SYMMETRIC_CIPHER_BLOCK_SIZE);
            numBytesToSkip = JceEncryptionConstants.SYMMETRIC_CIPHER_BLOCK_SIZE + offsetIntoBlock;
        }
        if(numBytesToSkip != 0) {
            // Skip to the left-most desired byte.  The read() method is used instead of the skip() method
            // since the skip() method will not block if the underlying input stream is waiting for more input.
            while(numBytesToSkip > 0) {
                this.decryptedContents.read();
                numBytesToSkip--;
            }
        }
        // The number of bytes the user may read is equal to the number of the bytes in the range.
        // Note that the range includes the endpoints.
        this.virtualAvailable = (rangeEnd - rangeBeginning) + 1;
    }
810743
private void readNextBlock()
            throws IOException
    {
        lastReadInputCheckpoint = input.getCheckpoint();

        int control = input.read();
        if (control == -1) {
            throw new OrcCorruptionException(input.getOrcDataSourceId(), "Read past end of buffer RLE byte");
        }

        offset = 0;

        // if byte high bit is not set, this is a repetition; otherwise it is a literal sequence
        if ((control & 0x80) == 0) {
            length = control + MIN_REPEAT_SIZE;

            // read the repeated value
            int value = input.read();
            if (value == -1) {
                throw new OrcCorruptionException(input.getOrcDataSourceId(), "Reading RLE byte got EOF");
            }

            // fill buffer with the value
            Arrays.fill(buffer, 0, length, (byte) value);
        }
        else {
            // length is 2's complement of byte
            length = 0x100 - control;

            // read the literals into the buffer
            input.readFully(buffer, 0, length);
        }
    }
778251
def _handle_end_node(self):
        
        self._result.append(Node(result=self._result, **self._curr))
        self._curr = {}
417516
async def readline(self) -> bytes:
        """"""
        if self._at_eof:
            return b''

        if self._unread:
            line = self._unread.popleft()
        else:
            line = await self._content.readline()

        if line.startswith(self._boundary):
            # the very last boundary may not come with \r\n,
            # so set single rules for everyone
            sline = line.rstrip(b'\r\n')
            boundary = self._boundary
            last_boundary = self._boundary + b'--'
            # ensure that we read exactly the boundary, not something alike
            if sline == boundary or sline == last_boundary:
                self._at_eof = True
                self._unread.append(line)
                return b''
        else:
            next_line = await self._content.readline()
            if next_line.startswith(self._boundary):
                # strip newline but only once
                line = line[:-len(self._newline)]
            self._unread.append(next_line)

        return line
19146
private void skipToEnd()
        throws IOException
    {
        InputStream is = getInputStream();

        if (is == null)
            return;

        if (chunkLength > 0)
            is.skip(chunkLength);

        for (int tag = is.read(); tag >= 0; tag = is.read()) {
            switch (tag) {
                case 'Y':
                    server.freeReadLock();
                    this.is = is = server.readChannel(channel);
                    if (is == null) {
                        this.server = null;
                        return;
                    }
                    break;

                case 'Q':
                    server.freeReadLock();
                    this.is = null;
                    this.server = null;
                    return;

                case -1:
                    server.freeReadLock();
                    this.is = null;
                    this.server = null;
                    return;

                default:
                    int length = (is.read() << 8) + is.read();
                    is.skip(length);
                    break;
            }
        }
    }
1240367
def finish(self):
        
        if self.state is not State.NORMAL:
            raise ReadError(f'EOF while in {self.state.name} state')
        if self.stack:
            top = self.stack[-1]
            top.raise_unclosed_error()
1316222
private boolean fillLast() throws IOException {
        int count;

        if (lastFilled == pageSize) {
            throw new IllegalStateException();
        }
        count = src.read(pages[lastNo], lastFilled, pageSize - lastFilled);
        if (count <= 0) {
            if (count == 0) {
                throw new IllegalStateException();
            }
            return false;
        }
        lastFilled += count;
        return true;
    }
419132
def get(self, start, end):
        
        return [self.read_byte(addr) for addr in range(start, end)]
199751
def get(self, start, end):
        
        return [self.read_byte(addr) for addr in xrange(start, end)]
150744
def read(self, n):
        

        d = b''
        while n:
            try:
                block = self._process.stdout.read(n)
            except ValueError:
                block = None
            if not block:
                self._process.poll()
                raise EOFError('Process ended')
            d += block
            n -= len(block)
        return d
152056
public void endObject() throws IOException {
    int p = peeked;
    if (p == PEEKED_NONE) {
      p = doPeek();
    }
    if (p == PEEKED_END_OBJECT) {
      stackSize--;
      pathNames[stackSize] = null; // Free the last path name so that it can be garbage collected!
      pathIndices[stackSize - 1]++;
      peeked = PEEKED_NONE;
    } else {
      throw new IllegalStateException("Expected END_OBJECT but was " + peek() + locationString());
    }
  }