Linux压缩库archive使用

2018-12-18  本文已影响34人  Lee_5566

读取初始化

archive_read_new()

Allocates and initializes a struct archive object suitable for reading from an archive.

分配和初始化适合从存档中读取的struct归档对象。

选择压缩或解压格式

archive_read_support_format_all(struct archive *)

Enables support for all available formats except the "raw" format.

支持除“原始”格式之外的所有可用格式.

archive_read_support_compression_all(),

1.archive_read_support_compression_bzip2(),
2.archive_read_support_compression_compress(),
3.archive_read_support_compression_gzip(),
4.archive_read_support_compression_none()
Enables auto-detection code and decompression support for the specified compression. Note that ``none'' is always enabled by default. For convenience,archive_read_support_compression_all() enables all available decompression code.

为指定的压缩启用自动检测代码和解压缩支持。请注意,默认情况下始终启用“无”。为方便起见,archive_read_support_compression_all启用所有可用的解压缩代码。

解压时写入磁盘

写入初始化

archive_write_disk_new()

Allocates and initializes a struct archive object suitable for writing objects to disk.

分配和初始化适合将对象写入磁盘的struct归档对象

设定写入的权限

archive_write_disk_set_options()

The options field consists of a bitwise OR of one or more of the following values:

ARCHIVE_EXTRACT_TIME
The timestamps (mtime, ctime, and atime) should by restored.By default, they are ignored. Note that restoring of atime is not currently supported.

应该通过恢复时间戳(mtime,ctime和atime)。默认情况下,它们会被忽略。注意目前不支持恢复atime。

ARCHIVE_EXTRACT_ACL
Attempt to restore Access Control Lists. By default,extended ACLs are ignored.

尝试还原访问控制列表。默认情况下,将忽略扩展ACL。

ARCHIVE_EXTRACT_FFLAGS
Attempt to restore file attributes (file flags).By default, file attributes are ignored.See chattr(1)(Linux) or chflags(1) (FreeBSD, Mac OS X) for more infor-mation on file attributes.

尝试恢复文件属性(文件标志)。默认情况下,将忽略文件属性。有关文件属性的更多信息,请参阅chattr(1)(Linux)或chflags(1)(FreeBSD,Mac OS X)。

ARCHIVE_EXTRACT_PERM
Full permissions (including SGID, SUID, and sticky bits) should be restored exactly as specified, without obeying the current umask.Note that SUID and SGID bits can only be restored if the user and group ID of the object on disk are correct. If ARCHIVE_EXTRACT_OWNER is not speci-fied, then SUID and SGID bits will only be restored if the default user and group IDs of newly-created objects on disk happen to match those specified in the archive
entry. By default, only basic permissions are restored, and umask is obeyed.

完全权限(包括SGID,SUID和粘滞位)应该完全按照指定进行恢复,而不必遵守
目前的umask。请注意,SUID和SGID位只能如果对象的用户和组ID在,则恢复磁盘是正确的。如果ARCHIVE_EXTRACT_OWNER不是speci-如果是,那么SUIDSGID位只会被恢复新创建的对象的默认用户和组ID磁盘碰巧与归档中指定的匹配条目。默认情况下,仅恢复基本权限,和umask遵守。

还有很多权限控制,请参考函数文档。

 archive_write_disk_set_standard_lookup()

This convenience function installs a standard set of user and group lookup functions. These functions use getpwnam(3) and getgrnam(3) to convert names to ids, defaulting to the idsif the names cannot be looked up. These functions also implement a sim-ple memory cache to reduce the number of calls to getpwnam(3) and getgrnam(3).

此便捷功能安装一组标准的用户和组查找功能。这些函数使用getpwnam(3)和getgrnam(3)将名称转换为id,如果无法查找名称,则默认为ids。这些函数还实现了一个简单的内存缓存,以减少对getpwnam(3)和getgrnam(3)的调用次数。

读取压缩包

 archive_read_open()

The same as archive_read_open2(), except that the skip callback is assumed to be NULL.

与archive_read_open2()相同,但跳过回调假定为NULL。

archive_read_open2()

Freeze the settings, open the archive, and prepare for reading entries. This is the most generic version of this call, which accepts four callback functions. Most clients will want to use archive_read_open_filename(),archive_read_open_FILE(),archive_read_open_fd(), or archive_read_open_memory() instead. The library invokes the client-provided functions to obtain raw bytes from the archive.

冻结设置,打开存档,并准备读取条目。这是此调用的最通用版本,它接受四个回调函数。大多数客户端都希望使用archive_read_open_filename(),archive_read_open_FILE(),archive_read_open_fd()或archive_read_open_memory()。库调用客户端提供的函数从存档中获取原始字节。

archive_read_open_filename()

Like archive_read_open(), except that it accepts a simple filename and a block size. A NULL filename represents standard input. This function is safe for use with tape drives or other blocked devices.

与archive_read_open()类似,不同之处在于它接受简单的文件名和块大小。 NULL文件名表示标准输入。此功能可安全用于磁带机或其他被阻止的设备。

archive_read_next_header()

Read the header for the next entry and return a pointer to a struct archive_entry. This is a convenience wrapper around archive_read_next_header2() that reuses an internal struct archive_entry object for each request.

读取下一个条目的标题,并返回指向struct archive_entry的指针。这是archive_read_next_header2()的便捷包装器,它为每个请求重用内部struct archive_entry对象。

archive_write_header()

Build and write a header using the data in the provided struct archive_entry structure. See ManPageArchiveEntry3 for information on creating and populating struct archive_entry objects.

使用提供的struct archive_entry结构中的数据构建和编写标头。有关创建和填充struct archive_entry对象的信息,请参阅ManPageArchiveEntry3。

上一篇下一篇

猜你喜欢

热点阅读