Exemplo n.º 1
0
    def from_header(header):
        """
        docstring
        """

        header = header[0:ZISOFS.get_header_size()]

        # Make sure is bytes
        if not isinstance(header, (bytes, bytearray)):
            raise ValueError
        # Header magic
        if header[0:8] != ZISOFS.hdr_magic:
            raise NotCompressedFile

        # Correct size
        if len(header) != 4 * iso711_to_int(ZISOFS.hdr_size):
            raise IllegalZisofsFormat

        # Header size
        if header[12:13] != ZISOFS.hdr_size:
            raise IllegalZisofsFormat

        zisofs_obj = ZISOFS()

        # File size
        zisofs_obj.size = header[8:12]

        # Blocksize
        if iso711_to_int(header[13:14]) not in default_block_sizes:
            raise IllegalZisofsFormat
        zisofs_obj.blocksize = header[13:14]

        return zisofs_obj
Exemplo n.º 2
0
    def from_header(header):
        """
        docstring
        """

        header = header[0:ZISOFSv2.get_header_size()]
        # Make sure is bytes
        if not isinstance(header, (bytes, bytearray)):
            raise ValueError
        # Header magic
        if header[0:8] != ZISOFSv2.hdr_magic:
            raise NotCompressedFile

        # Correct size
        if len(header) != 4 * iso711_to_int(ZISOFSv2.hdr_size):
            raise IllegalZisofsFormat

        # Header size
        if header[9:10] != ZISOFSv2.hdr_size:
            raise IllegalZisofsFormat

        zisofs_obj = ZISOFSv2()

        # Algorithm
        if iso711_to_int(header[10:11]) == 0:
            raise IllegalZisofsFormat
        zisofs_obj.alg_id = header[10:11]

        # Blocksize
        if iso711_to_int(header[11:12]) not in default_block_sizes:
            raise IllegalZisofsFormat
        zisofs_obj.blocksize = header[11:12]

        # File size
        zisofs_obj.size = header[12:20]

        return zisofs_obj
Exemplo n.º 3
0
 def __len__(self):
     return 4 * iso711_to_int(self.hdr_size)
Exemplo n.º 4
0
 def get_blocksize(self):
     # ZISOFS.blocksize = int_to_iso711(int(math.log(blocksize, 2)))
     return 2**iso711_to_int(self.blocksize)
Exemplo n.º 5
0
 def get_header_size(cls):
     """
     docstring
     """
     return 4 * iso711_to_int(cls.hdr_size)
Exemplo n.º 6
0
 def get_algorithm(self):
     """
     docstring
     """
     return Algorithm(iso711_to_int(self.alg_id))