Exemple #1
0
 def _generate_files_block(self, files_position):
     """ Generate the files block and update entries with the correct data
     position. """
     # Using an IO because we repeatedly pad the bytes.
     data_io = io.BytesIO()
     position = files_position
     for entry in self.entries:
         entry.data_position = position
         data_io.write(entry.data)
         pad_file(data_io, 16)
         position = files_position + data_io.tell()
     return data_io.getvalue()
Exemple #2
0
    def import_file(self, file_path):
        position = self.bdt_file.tell()
        try:
            with open(file_path, "rb") as input_file:
                file_content = input_file.read()
            num_written = self.bdt_file.write(file_content)

            # Pad the BDT file to 16-byte if needed.
            pad_file(self.bdt_file, 16)
        except OSError as exc:
            LOG.error("Error importing {}: {}".format(
                file_path, exc
            ))
            return position, -1
        else:
            return position, num_written