ZipOptions
ZipOptions 是 zip 模块的压缩 / 解压选项对象, 会被转换为 Zip4j 的 ZipParameters 和 UnzipParameters.
源码依据:
app/src/main/java/org/autojs/autojs/runtime/api/augment/zip/Zip.ktapp/src/main/java/org/autojs/autojs/runtime/api/augment/zip/ZipNativeObject.kt
常见相关方法或属性:
- zip.open(zipPath, options)
- zip.zipFile(filePath, destZipPath, options)
- zip.zipDir(filePath, destZipPath, options)
- zip.zipFiles(filePathList, destZipPath, options)
- zip.unzip(zipPath, destPath, options)
- ZipNativeObject.addFile(filePath, options)
- ZipNativeObject.extractAll(destPath, options)
ZipOptions
压缩选项
- password { string } - ZIP 密码. 设置后会调用
zipFile.setPassword(...), 并自动将encryptFiles设为true. - aesKeyStrength { number | string } - 默认
256. 数字支持128/192/256; 字符串支持128/192/256或 Zip4j 枚举名. - aesVersion { number | string } - 默认
2. 支持1/2或ONE/TWO. - compressionLevel { number | string } - 默认
NORMAL. 数字按 Zip4jCompressionLevel.level匹配; 字符串可使用去掉DEFLATE_LEVEL_前缀后的枚举名. - compressionMethod { number | string } - 默认
DEFLATE. 数字按 Zip4jCompressionMethod.code匹配; 字符串可使用去掉COMP_前缀后的枚举名. - encryptionMethod { number | string } - 默认
AES. 数字支持-1=NONE,0=ZIP_STANDARD,1=ZIP_STANDARD_VARIANT_STRONG,99=AES. - defaultFolderPath { string }
- entryCRC { number }
- entrySize { number }
- excludeFileFilter { function |
ExcludeFileFilter} - 返回true时排除文件. - fileComment / comment { string }
- fileNameInZip { string }
- isIncludeRootFolder / includeRootFolder { boolean }
- isOverrideExistingFilesInZip / overrideExistingFilesInZip { boolean }
- isReadHiddenFiles / readHiddenFiles { boolean }
- isReadHiddenFolders / readHiddenFolders { boolean }
- isUnixMode / unixMode { boolean }
- isWriteExtendedLocalFileHeader / writeExtendedLocalFileHeader { boolean }
- lastModifiedFileTime { number }
- rootFolderNameInZip { string }
- symbolicLinkAction { string } - 默认
INCLUDE_LINKED_FILE_ONLY, 字符串必须能匹配 Zip4jSymbolicLinkAction枚举. - isEncryptFiles / encryptFiles { boolean }
解压选项
- password { string } - 解压加密 ZIP 时使用.
- isExtractSymbolicLinks { boolean } - 当前源码读取此项, 默认
true; 但没有写回UnzipParameters, 行为以 Zip4j 默认值为准.
异常与边界
options必须是 JavaScript 对象;null/undefined会按空对象处理.excludeFileFilter只能是 Zip4jExcludeFileFilter或 JavaScript 函数; 其他值会抛出参数异常.aesKeyStrength,compressionLevel,compressionMethod,encryptionMethod,symbolicLinkAction等枚举字段传入非法值时会抛出异常.ignoreDateTimeAttributes/isIgnoreDateTimeAttributes在当前 Zip4j 2.x 实现中不再支持. 传入这些选项会抛出异常.
示例
js
let z = zip.zipFiles([
'./logs/a.txt',
'./logs/b.txt',
], './logs.zip', {
password: 'secret',
compressionLevel: 'MAXIMUM',
aesKeyStrength: 256,
includeRootFolder: false,
});
console.log(z.isEncrypted());