gpt4 book ai didi

c - 如何解压内存中的文件(c 编程)?

转载 作者:太空狗 更新时间:2023-10-29 15:11:11 31 4
gpt4 key购买 nike

让我解释一下我想要实现的目标:

我有一个加密的 tar 文件。我可以在内存中解密,但显然我不能将解密后的数据作为真实文件写回硬盘。解密后的数据在内存中被构造为一个 char* 缓冲区;我如何在内存中解压它?

我找不到 libtar 库的答案。我还尝试使用 execlp("tar", "tar", "-xvO", (void*)0) 解压它。但它并没有像我想的那样起作用。

谁能给我一些最佳解决方案的提示?谢谢!

最佳答案

我怀疑libtar就是答案。

使用 libtar,您可以指定自己的打开/关闭、读取和写入函数。从联机帮助页:

int tar_open(TAR **t, char *pathname, tartype_t *type, int oflags,
int mode, int options);

The tar_open() function opens a tar archive file corresponding to the filename named by the pathname argument. The oflags argument must be either O_RDONLY or O_WRONLY.

The type argument specifies the access methods for the given file type. The tartype_t structure has members named openfunc(), closefunc(), readfunc() and writefunc(), which are pointers to the functions for opening, closing, reading, and writing the file, respectively. If type is NULL, the file type defaults to a normal file, and the standard open(), close(), read(), and write() functions are used.

关于c - 如何解压内存中的文件(c 编程)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1553653/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com