Esempio n. 1
0
def read_gints(dbfile, n):
    """Read N integers from the bytes stream dbfile. Expects that the file
    starts at a key byte.
    """

    count = 0
    read = dbfile.read
    for _ in xrange(n):
        if count == 0:
            key = ord(dbfile.read(1))
        code = key >> (count * 2) & 3
        if code == 0:
            yield ord(read(1))
        elif code == 1:
            yield unpack_ushort_le(read(2))[0]
        elif code == 2:
            yield unpack_uint_le(read(3) + "\x00")[0]
        else:
            yield unpack_uint_le(read(4))[0]

        count = (count + 1) % 4
Esempio n. 2
0
def read_gints(dbfile, n):
    """Read N integers from the bytes stream dbfile. Expects that the file
    starts at a key byte.
    """

    count = 0
    read = dbfile.read
    for _ in xrange(n):
        if count == 0:
            key = ord(dbfile.read(1))
        code = key >> (count * 2) & 3
        if code == 0:
            yield ord(read(1))
        elif code == 1:
            yield unpack_ushort_le(read(2))[0]
        elif code == 2:
            yield unpack_uint_le(read(3) + "\x00")[0]
        else:
            yield unpack_uint_le(read(4))[0]

        count = (count + 1) % 4
Esempio n. 3
0
 def read_ushort_le(self):
     return unpack_ushort_le(self.read(_SHORT_SIZE))[0]
Esempio n. 4
0
 def read_ushort_le(self):
     return unpack_ushort_le(self.read(_SHORT_SIZE))[0]