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 pathdestPath(string) - Extraction destination directorypassword(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 compressarchivePath(string) - Output archive file pathpassword(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 pathpassword(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