def save(self, vpk_output_path):
with fopen(vpk_output_path, '<STR_LIT:wb>') as f:<EOL><INDENT>f.write(struct.pack("<STR_LIT>", self.signature,<EOL>self.version,<EOL>self.tree_length))<EOL>self.header_length = f.tell()<EOL>data_offset = self.header_length + self.tree_length<EOL>for ext in self.tree:<EOL><INDENT>f.write("<STR_LIT>".format(ext).encode('<STR_LIT>'))<EOL>for relpath in self.tree[ext]:<EOL><INDENT>f.write("<STR_LIT>".format(relpath).encode('<STR_LIT>'))<EOL>for filename in self.tree[ext][relpath]:<EOL><INDENT>f.write("<STR_LIT>".format(filename).encode('<STR_LIT>'))<EOL>metadata_offset = f.tell()<EOL>file_offset = data_offset<EOL>real_filename = filename if not ext else "<STR_LIT>".format(filename, ext)<EOL>checksum = <NUM_LIT:0><EOL>f.seek(data_offset)<EOL>with fopen(os.path.join(self.path,<EOL>'<STR_LIT>' if relpath == '<STR_LIT:U+0020>' else relpath,<EOL>real_filename<EOL>),<EOL>'<STR_LIT:rb>') as pakfile:<EOL><INDENT>for chunk in iter(lambda: pakfile.read(<NUM_LIT>), b'<STR_LIT>'):<EOL><INDENT>checksum = crc32(chunk, checksum)<EOL>f.write(chunk)<EOL><DEDENT><DEDENT>data_offset = f.tell()<EOL>file_length = f.tell() - file_offset<EOL>f.seek(metadata_offset)<EOL>f.write(struct.pack("<STR_LIT>", checksum & <NUM_LIT>,<EOL><NUM_LIT:0>,<EOL><NUM_LIT>,<EOL>file_offset - self.tree_length - self.header_length,<EOL>file_length,<EOL><NUM_LIT><EOL>))<EOL><DEDENT>f.write(b"<STR_LIT:\x00>")<EOL><DEDENT>f.write(b"<STR_LIT:\x00>")<EOL><DEDENT>f.write(b"<STR_LIT:\x00>")<EOL><DEDENT>
Saves the VPK at the given path