libzip的src目录下包括ziptool.c,在build目录下make之后,它的二进制文件保存在build/src目录下。
以下是它的帮助信息
./ziptool -h
usage: ./ziptool [-ceghnrst] [-l len] [-o offset] archive command1 [args] [command2 [args] ...]
Supported options are:
-c check consistency
-e error if archive already exists (only useful with -n)
-g guess file name encoding (for stat)
-h display this usage
-l len only use len bytes of file
-n create archive if it doesn't exist
-o offset start reading file at offset
-r print raw file name encoding without translation (for stat)
-s follow file name convention strictly (for stat)
-t disregard current archive contents, if any
Supported commands and arguments are:
add name content
add file called name using content
add_dir name
add directory
add_file name file_to_add offset len
add file to archive, len bytes starting from offset
add_from_zip name archivename index offset len
add file from another archive, len bytes starting from offset
cat index
output file contents to stdout
cat_partial index start length
output partial file contents to stdout
count_extra index flags
show number of extra fields for archive entry
count_extra_by_id index extra_id flags
show number of extra fields of type extra_id for archive entry
delete index
remove entry
delete_extra index extra_idx flags
remove extra field
delete_extra_by_id index extra_id extra_index flags
remove extra field of type extra_id
get_archive_comment
show archive comment
get_archive_flag flag
show archive flag
get_extra index extra_index flags
show extra field
get_extra_by_id index extra_id extra_index flags
show extra field of type extra_id
get_file_comment index
get file comment
get_num_entries flags
get number of entries in archive
name_locate name flags
find entry in archive
print_progress
print progress during zip_close()
rename index name
rename entry
replace_file_contents index data
replace entry with data
set_archive_comment comment
set archive comment
set_archive_flag flag
set archive flag
set_extra index extra_id extra_index flags value
set extra field
set_file_comment index comment
set file comment
set_file_compression index method compression_flags
set file compression method
set_file_dostime index time date
set file modification time and date (DOS format)
set_file_encryption index method password
set file encryption method
set_file_mtime index timestamp
set file modification time
set_file_mtime_all timestamp
set file modification time for all files
set_password password
set default password for encryption
stat index
print information about entry
Supported flags are:
0 (no flags)
4 ZIP_FL_ENC_CP437
8 ZIP_FL_ENC_UTF_8
C ZIP_FL_NOCASE
c ZIP_FL_CENTRAL
d ZIP_FL_NODIR
l ZIP_FL_LOCAL
r ZIP_FL_ENC_RAW
s ZIP_FL_ENC_STRICT
u ZIP_FL_UNCHANGED
Supported archive flags are:
create-or-keep-empty-file-for-archive
is-torrentzip
rdonly
want-torrentzip
Supported compression methods are:
default
deflate
store
xz
zstd
Supported encryption methods are:
none
AES-128
AES-192
AES-256
PKWARE
The index is zero-based.
可见,它的功能主要是:
1.对已有zip文件相关元数据和数据的查看,一般以get开头
2.往zip文件中添加注释、元数据等,一般以set开头
3.往zip文件中添加条目,以add开头
4.删除zip文件中的条目,一般以delete开头
举例如下:(注意第一个参数必须是有效的zip文件名,不然会出一些奇怪的问题)
#添加压缩包文件注释并查看
./ziptool /shujv/par/top5.zip set_archive_comment 'zip format using zstd'
./ziptool /shujv/par/top5.zip get_archive_comment
Archive comment: zip format using zstd
#添加条目文件注释并查看,1是文件索引号
./ziptool /shujv/par/top5.zip set_file_comment 1 "this file is an xlsx"
./ziptool /shujv/par/top5.zip get_file_comment 1
File comment for 'docProps/app.xml': this file is an xlsx
#查看条目元数据,1是文件索引号,93是zstd算法的代号
./ziptool /shujv/par/top5.zip stat 1
name: 'docProps/app.xml'
index: '1'
size: '205'
compressed size: '163'
mtime: 'Wed Aug 27 2025 16:00:44'
crc: '484dc746'
compression method: '93'
encryption method: '0'
#查看条目文件部分数据,1是文件索引号
./ziptool /shujv/par/top5.zip cat_partial 1 1 50
Properties xmlns="http://schemas.openxmlformats.or
#查看一个xls文件改名的zip文件,报错
./ziptool /shujv/par/menu.xls.zip stat 0
can't open zip archive '/shujv/par/menu.xls.zip': Not a zip archive
890

被折叠的 条评论
为什么被折叠?



