app.archive - Archive API

Compress and extract files.

Supported Formats

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

Methods

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

Extract an archive file.

Parameters:

  • archivePath (string) - Archive file path
  • destPath (string) - Extraction destination directory
  • password (string, optional) - Password

Returns: boolean, error - Whether successful; returns false, error on failure

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

-- Extract an encrypted zip
app.archive.extract("/path/to/encrypted.zip", "/path/to/output", "password123")

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

Compress a file or directory.

Parameters:

  • sourcePath (string) - Path of the file or directory to compress
  • archivePath (string) - Output archive file path
  • password (string, optional) - Password

Returns: boolean, error - Whether successful; returns false, error on failure

-- Compress a directory
local ok, err = app.archive.compress("/path/to/folder", "/path/to/output.zip")

-- Compress with encryption
app.archive.compress("/path/to/folder", "/path/to/output.zip", "password123")

app.archive.list(archivePath, password?)

List archive contents.

Parameters:

  • archivePath (string) - Archive file path
  • password (string, optional) - Password

Returns: table, error - Array of file paths; returns nil, error on failure

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

Examples

Extract Selected Files

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("Done", "Extracted: " .. app.path.basename(file))
            else
                app.notification.show("Failed", "Extraction failed: " .. app.path.basename(file))
            end
        end
    end
end

Compress Selected Folders

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("Done", "Compressed: " .. app.path.basename(zipPath))
            end
        end
    end
end
Developer Documentation
User Guide
Getting Started Script Menus FAQ
Script Development
Development Guide
Plugin Development
Quick Start Development Guide Example Plugins
API Reference
Overview API Query Plugin Info Logging Finder Context Plugin Settings Internationalization
UI & Interaction
Dialog Progress Notification Chooser WebView Status Bar Dock
Files & Paths
File Operations Path Utilities Finder Actions Trash Extended Attributes Metadata File Watcher
Data Formats
JSON Plist CSV XML PDF Image
Text & Encoding
String Regex Date & Time Color Crypto
System
Shell Commands Process Application System Info AppleScript Shortcuts
System Info
Network Power/Battery Screen/Appearance Audio Bluetooth Location
Network
HTTP WebSocket URL
Input & Clipboard
Keyboard Mouse Hotkey Clipboard Window
Storage
SQLite Keychain UserDefaults
Media
OCR QR Code
Utilities
Archive UTI Share Timer Wake Lock Thread