Zip.async.extract(path, [dir], [use_entrypath]) method
Extract on the disk an entry with the given path/name in the Zip archive, asynchronously. The Zip archive should have been previously opened in "read" mode.
Parameters
path
A string representing the path and/or the name of the entry in the Zip archive to be extracted.
dir
An optional destination folder where the entry will be extracted on the disk, as a string or a Directory value.
If omitted, the entry will be extracted in the current directory.
[use_entrypath]
An optional boolean value that indicates to extract the entry conserving its path or not.
Return value
This function returns a Task executed in background.Once the Task has terminated the entry extraction, it will return one of the following possible values :
- File representing the extracted file on the disk.
- Directory representing the extracted directory on the disk.
- false if any error occured. You can check the Zip.error property to get the error message.
Example
-- extract an entry from a zip archive
local compression = require "compression"
-- check parameters : the archive and entry specified as argument
local archive = arg[1] or error("no archive specified")
local entry = arg[2] or error("no entry specified")
-- open the archive
local z = compression.Zip(archive)
-- extract the entry on the disk asynchronously or throws an error if false
local extracted = await(z:extract(entry) or error(z.error))
print(extracted.name.." has been successfully extracted to "..extracted.path)