如何使用"PhysicsFS"归档和压缩数据

the*_*ean 4 c++ archive

我正在查看"PhysicsFS"文档并搜索存档和压缩数据但无法找到的方法.它是否可能,如果它是我如何做到这一点

Gig*_*igi 7

PhysicsFS zip支持

PhysicsFS支持从安装在它提供的"虚拟文件系统"中任意点的zip文件中读取文件.这有效地提供了ZIP存档的解压缩.

但是,PhysicsFS不支持添加或修改ZIP存档的内容.它只允许在其文档中的"写入目录"中写入未压缩的文件.

因此,总结一下:PhysicsFS仅支持从ZIP存档读取,而不是写入它.对于压缩,您可以自己动手:如果需要,只需使用外部压缩器压缩所有写入的文件.


PhysicsFS用法

没有为PhysicsFS一个小教程在这里.

它使用起来非常简单:

// initialize the lib
PHYSFS_init(NULL);

// "mount" a zip file in the root directory
PHYSFS_AddToSearchPath("myzip.zip", 1);

// set a directory for writing
PHYSFS_setWriteDir(const char *newDir);

// open a file for reading
PHYSFS_file* myfile = PHYSFS_openRead("myfile.txt");

// open a file for writing
PHYSFS_file* myfile = PHYSFS_openWrite("output_file.bin");

// get a file size
PHYSFS_sint64 file_size = PHYSFS_fileLength(myfile);

// read data from a file (decompress only if path is inside a zip mount point)
char* myBuf = new char[file_size];
int length_readed = PHYSFS_read(myfile, myBuf, 1, file_size);

// write data to a file (uncompressed)
char* myBuf = new char[new_file_size];
//...fill myBuf...
int length_writed = PHYSFS_write(myfile, myBuf, 1, new_file_size);

// close a file
PHYSFS_close(myfile);

// deinitialize the lib
PHYSFS_deinit();
Run Code Online (Sandbox Code Playgroud)