Zip:write(entry, [path]) method
Writes a new entry in the Zip archive. The Zip archive should have been previously opened in "write" or "append" mode.
Parameters
entry
The new entry to be written in the Zip archive. An entry can be :
- A string that represents a filename or directory whose contents will be archived. A Buffer whose binary content will be archived at the specified path.
- A File value whose content will be archived.
- A Directory value whose content will be archived
path
An optional string representing the path and/or the name of the new entry in the Zip archive. If omitted, the new entry will be archived at the root of the Zip archive, using the name provided by the entry parameter.
Return value
Returns true if entry has been successfully added to the zip archive or false otherwise. You can check the Zip.error property to get the error message.Example
-- zip script
local compression = require "compression"
-- check if the file specified as argument exists
local f = sys.File(arg[1] or error("no file specified"))
if f.exists then
--- create a zip archive file with the same name
local archive = compression.Zip(f.name:gsub(f.extension, ".zip"), "write")
--- add the file to the archive
archive:write(f)
else
error(f.name.." not found")
end