compression.isZip(file)

The isZip() function checks wether a file represent a valid ZIP archive.

Parameters

file

A string or a File object, to be checked for ZIP validity.

Return value

Returns true if the given file is a valid ZIP archive, false otherwise.

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") -- check that the file is a valid ZIP archive if not compression.isZip(archive) then error("'"..archive.."' is not a valid ZIP archive, or may be corrupted") end -- open the archive local z = compression.Zip(archive) -- extract the entry on the disk in the current directory or throws an error if false local extracted = z:extract(entry) or error(z.error) print(extracted.name.." has been successfully extracted to "..extracted.path)