def buffered_read(fh, lock, offsets, bytecounts, buffersize=None):
    """Return iterator over segments read from file."""
    if buffersize is None:
        buffersize = 2**26
    length = len(offsets)
    i = 0
    while i < length:
        data = []
        with lock:
            size = 0
            while size < buffersize and i < length:
                fh.seek(offsets[i])
                bytecount = bytecounts[i]
                data.append(fh.read(bytecount))
                # buffer = bytearray(bytecount)
                # n = fh.readinto(buffer)
                # data.append(buffer[:n])
                size += bytecount
                i += 1
        for segment in data:
            yield segment
def buffered_read ( fh , lock , offsets , bytecounts , buffersize = None ) : if buffersize is None : buffersize = 2 ** 26 length = len ( offsets ) i = 0 while i < length : data = [ ] with lock : size = 0 while size < buffersize and i < length : fh . seek ( offsets [ i ] ) bytecount = bytecounts [ i ] data . append ( fh . read ( bytecount ) ) size += bytecount i += 1 for segment in data : yield segment
Return iterator over segments read from file.