zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

【Android 安装包优化】7z 文件压缩格式 ( 7z 格式简介 | 7z 命令使用说明 )

Android文件安装包命令 使用 优化 说明 简介
2023-06-13 09:17:49 时间

文章目录

一、7z 文件压缩格式简介


7z 文件压缩格式 , 压缩比很高 , 压缩时可以选择多种压缩算法 , 该算法比 zip , tar , rar 等压缩格式的压缩比率更高 , 得到的压缩后的文件最小 ;

7-Zip 简介 : 开源压缩软件 , 压缩比率高 , 压缩时消耗的资源也多 ; 支持 7z , xz , bzip2 , gzip , tar , zip , wim 等压缩格式 , 不支持 rar 格式 ( 这个还在专利保护期内 ) ;

7-Zip 软件压缩比率 , 比 WinZip , WinRAR , 等压缩任何格式都要高 , 包括 zip 和 rar 格式 ;

从压缩时间进行分析 , 使用快速压缩模式 , 7-Zip 比其他软件都快 , 如果使用高压缩比率模式 , 7-Zip 压缩比其它压缩工具慢 ;

二、7z 命令使用说明


1、压缩命令

7z 压缩命令 :

7z a  outputFile inputFile -mx=compressDegree -tcompressType

其中 a 代表 add 的含义 ;

outputFile 是输出文件 ;

inputFile 表示输入文件 ;

-mx=compressDegree 用于设置压缩等级 , compressDegree 取值范围 { 0 , 1, 5, 7,9 } ;

-tcompressType 表示压缩类型 , -t7z 表示压缩格式为 7z , -tzip 表示压缩格式是 zip 格式 ;

压缩等级含义 :

  • 0 : 不压缩 , 只存储 ;
  • 1 : 快速压缩 ;
  • 5 : 正常压缩 ;
  • 7 : 最大压缩 ;
  • 9 : 极限压缩 ;

2、解压命令

7z 解压缩命令 :

7z x [输入文件] -o[输出目录]

输入文件指的就是压缩文件 ;

输出目录就是将压缩文件解压到哪 ;

注意 : -o 与输出目录之间没有空格 ;

三、7z 命令示例


1、配置 7z 命令环境变量

将 7zip 安装目录 A:\Program Files\7-Zip 配置到 Path 环境变量中 ;

配置环境变量 ;

配置完成后 , 可以在任意目录中调用 7z 命令了 ;

2、压缩

7z 压缩命令 : 将本目录压缩到 string.7z 压缩包中 , 压缩等级设置为极限压缩 ;

7z a string.7z . -mx=9

命令行输出 :

D:\develop\7zip>7z a string.7z . -mx=9

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Scanning the drive:
1 file, 23361 bytes (23 KiB)

Creating archive: string.7z

Add new data to archive: 1 file, 23361 bytes (23 KiB)


Files read from disk: 1
Archive size: 5438 bytes (6 KiB)
Everything is Ok

D:\develop\7zip>

压缩结果 : 23KB 的 XML 文本文件被压缩层 6KB ;

3、解压缩

7z 解压缩命令 : 将 string.7z 解压 , 输出到 output 目录中 ;

7z x string.7z -ooutput

命令行输出 :

D:\develop\7zip>7z x string.7z -ooutput

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Scanning the drive for archives:
1 file, 5438 bytes (6 KiB)

Extracting archive: string.7z
--
Path = string.7z
Type = 7z
Physical Size = 5438
Headers Size = 130
Method = LZMA2:24k
Solid = -
Blocks = 1

Everything is Ok

Size:       23361
Compressed: 5438

D:\develop\7zip>

解压结果 : string.7z 解压到了 output 目录中 ;

四、参考资料


参考资料 :