ZipUtil class
压缩解压工具类
使用示例:
// 压缩文件(不加密)
try {
final zipPath = await ZipUtil.zip(
'/path/to/source',
'/path/to/output.zip'
);
print('压缩成功:$zipPath');
} catch (e) {
print('压缩失败:$e');
}
// 加密压缩
try {
final zipPath = await ZipUtil.zipWithPassword(
'/path/to/source',
'/path/to/encrypted.zip',
'your_password'
);
print('加密压缩成功:$zipPath');
} catch (e) {
print('加密压缩失败:$e');
}
// 解压文件(不需要密码)
try {
final files = await ZipUtil.unzip(
'/path/to/archive.zip',
'/path/to/extract'
);
print('解压成功,文件列表:$files');
} catch (e) {
print('解压失败:$e');
}
// 解密并解压
try {
final files = await ZipUtil.unzipWithPassword(
'/path/to/encrypted.zip',
'/path/to/extract',
'your_password'
);
print('解密解压成功,文件列表:$files');
} catch (e) {
print('解密解压失败:$e');
}
Constructors
- ZipUtil()
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
unzip(
String zipPath, String targetPath) → Future< List< String> > - 解压缩(不需要密码)
-
unzipWithPassword(
String zipPath, String targetPath, String password) → Future< List< String> > - 使用密码解压缩
-
zip(
String sourcePath, String targetPath) → Future< String> -
压缩文件/文件夹(不加密)
sourcePath源文件/文件夹路径targetPath目标zip文件路径 -
zipWithPassword(
String sourcePath, String targetPath, String password) → Future< String> - 使用密码压缩文件/文件夹