Esempio n. 1
0
    def read_block(cls, fh, start):
        fh.seek(start)
        magic = fh.read(cls.SIZE_MAGIC)
        if magic != cls.MAGIC_BYTES:
            raise PyDBInternalError(
                "Not a block at start position: {}.".format(start))

        size = bytes_to_int(fh.read(cls.SIZE_SIZE))
        nxt = bytes_to_int(fh.read(cls.SIZE_NEXT))
        prev = bytes_to_int(fh.read(cls.SIZE_PREV))
        next_empty = bytes_to_int(fh.read(cls.SIZE_NEXT_EMPTY))
        return cls(start, size, nxt, prev, next_empty=next_empty)
Esempio n. 2
0
def test_bytes_to_int():
    assert bytes_to_int(b'){\x8a\x83\xdc\x03O\x8e') == 2989135076627009422
Esempio n. 3
0
 def read_header(self):
     self.io.seek(0)
     self.count = bytes_to_int(self.io.read(self.SIZE_HEADER))
Esempio n. 4
0
 def decode_header(cls, barr):
     arr = b''.join(islice(barr, 0, TypeHeader.SIZE_TOTAL))
     null = bytes_to_int(arr[0:cls.SIZE_NULL])
     size = bytes_to_int(arr[cls.SIZE_NULL:cls.SIZE_NULL + cls.SIZE_SIZE])
     return TypeHeader(null, size)
Esempio n. 5
0
 def decode_value(self, val):
     return bytes_to_int(val)
Esempio n. 6
0
 def read_structure(self, fh, header_structure):
     self.header.seek(0)
     it = self.header.iterdata(chunk_size=4)
     it = ((a, b, bytes_to_int(c)) for a, b, c in it)
     super_blocks_pos = [x[2] for x in takewhile(lambda x: x[2] != -1, it)]
     return [BlockStructure(fh, x) for x in super_blocks_pos]