app.archive - 归档 API

压缩和解压文件。

支持格式

zip, ipa, apk, tar, tar.gz, tar.bz2, 7z

方法

app.archive.extract(archivePath, destPath, password?)

解压归档文件。

参数:

  • archivePath (string) - 归档文件路径
  • destPath (string) - 解压目标目录
  • password (string, 可选) - 密码

返回值: boolean, error - 是否成功,失败时返回 false, error

-- 解压 zip
local ok, err = app.archive.extract("/path/to/file.zip", "/path/to/output")

-- 解压加密的 zip
app.archive.extract("/path/to/encrypted.zip", "/path/to/output", "password123")

app.archive.compress(sourcePath, archivePath, password?)

压缩文件或目录。

参数:

  • sourcePath (string) - 要压缩的文件或目录路径
  • archivePath (string) - 输出归档文件路径
  • password (string, 可选) - 密码

返回值: boolean, error - 是否成功,失败时返回 false, error

-- 压缩目录
local ok, err = app.archive.compress("/path/to/folder", "/path/to/output.zip")

-- 压缩并加密
app.archive.compress("/path/to/folder", "/path/to/output.zip", "password123")

app.archive.list(archivePath, password?)

列出归档内容。

参数:

  • archivePath (string) - 归档文件路径
  • password (string, 可选) - 密码

返回值: table, error - 文件路径数组,失败时返回 nil, error

local files = app.archive.list("/path/to/file.zip")
if files then
    for _, f in ipairs(files) do
        app.log.info(f)
    end
end

示例

解压选中的文件

function MyPlugin:handleExtract(context)
    for _, file in ipairs(context.selectedFiles) do
        local ext = app.path.extension(file)
        if ext == "zip" or ext == "tar" or ext == "gz" then
            local destDir = app.path.removeExtension(file)
            if app.archive.extract(file, destDir) then
                app.notification.show("完成", "已解压: " .. app.path.basename(file))
            else
                app.notification.show("失败", "解压失败: " .. app.path.basename(file))
            end
        end
    end
end

压缩选中的文件夹

function MyPlugin:handleCompress(context)
    for _, file in ipairs(context.selectedFiles) do
        if app.file.isDirectory(file) then
            local zipPath = file .. ".zip"
            if app.archive.compress(file, zipPath) then
                app.notification.show("完成", "已压缩: " .. app.path.basename(zipPath))
            end
        end
    end
end
开发者文档
使用帮助
使用说明 脚本菜单 常见问题
脚本开发
开发指南
插件开发
快速开始 开发指南 示例插件
API 参考
概览 API 查询 插件信息 日志 Finder 上下文 插件设置 国际化
UI 与交互
对话框 进度条 系统通知 选择器 WebView 状态栏 Dock
文件与路径
文件操作 路径工具 Finder 操作 废纸篓 扩展属性 元数据 文件监听
数据格式
JSON Plist CSV XML PDF 图片
文本与编码
字符串 正则表达式 日期时间 颜色 加密编码
系统
Shell 命令 进程管理 应用管理 系统信息 AppleScript 快捷指令
系统信息
网络信息 电源/电池 屏幕/外观 音频控制 蓝牙设备 位置服务
网络
HTTP 请求 WebSocket URL 工具
输入与剪贴板
键盘模拟 鼠标模拟 全局热键 剪贴板 窗口管理
存储
SQLite Keychain UserDefaults
媒体
文字识别 二维码
工具
归档 类型标识 分享 定时器 防休眠 并发/协程