LuaSTG-x Core API
lstg::ZipArchive Class Reference
Inheritance diagram for lstg::ZipArchive:

Classes

class  OpenMode
 
class  State
 

Public Member Functions

function addData (local entry, local data)
 
function addEntry (local entry)
 
function addFile (local entry, local file)
 
function addString (local entry, local string)
 
function close ()
 
function create (local path, local password)
 
function createFromBuffer (local buffer, local mode, local checkConsistency)
 
function deleteEntry (local entry)
 
function discard ()
 
function extractEntry (local entry, local dstPath, local state)
 
function getComment ()
 
function getEntries ()
 
function getEntryByIndex (local index, local state)
 
function getEntryComment (local entry, local state)
 
function getEntryCount ()
 
function getEntryInfo (local entry, local state)
 
function getMode ()
 
function hasEntry (local entry, local excludeDirectories, local caseSensitive, local state)
 
function isEncrypted ()
 
function isEntryCompressionEnabled (local entry, local state)
 
function isMutable ()
 
function isOpen ()
 
function open (local mode, local checkConsistency)
 
function readEntry (local entry, local state)
 
function removeComment ()
 
function renameEntry (local entry, local newName)
 
function setComment (local comment)
 
function setEntryComment (local entry, local comment, local state)
 
function setEntryCompressionEnabled (local entry, local value, local state)
 
function unlink ()
 

Member Function Documentation

◆ addData()

function addData ( local  entry,
local  data 
)

Adds the given data to the specified entry name in the archive. If the entry already exists,

its content will be erased.

If the entry contains folders that don't exist in the archive, they will be automatically created.

If the entry denotes a directory, this method returns false.

If the zip file is not open, this method returns false.

Parameters
entrystring
datalstg.Buffer
Returns
boolean

◆ addEntry()

function addEntry ( local  entry)

Adds the specified entry to the ZipArchive. All the needed hierarchy will be created.

The entryName must be a directory (end with '/').

If the ZipArchive is not open or the entryName is not a directory, this method will

returns false. If the entry already exists, this method returns true.

This method will only add the specified entry. The 'real' directory may exist or not.

If the directory exists, the files in it won't be added to the archive.

Parameters
entrystring
Returns
boolean

◆ addFile()

function addFile ( local  entry,
local  file 
)

Adds the specified file in the archive with the given entry. If the entry already exists,

it will be replaced. This method returns true if the file has been added successfully.

If the entry contains folders that don't exist in the archive, they will be automatically created.

If the entry denotes a directory, this method returns false.

The zip file must be open otherwise false will be returned.

Parameters
entrystring
filestring
Returns
boolean

◆ addString()

function addString ( local  entry,
local  string 
)

Adds the given string to the specified entry name in the archive. If the entry already exists,

its content will be erased.

If the entry contains folders that don't exist in the archive, they will be automatically created.

If the entry denotes a directory, this method returns false.

If the zip file is not open, this method returns false.

Parameters
entrystring
stringstring
Returns
boolean

◆ close()

function close ( )

Closes the ZipArchive and releases all the resources held by it. If the ZipArchive was

not open previously, this method does nothing. If the archive was open in modification

and some were done, they will be committed.

Returns
boolean

◆ create()

function create ( local  path,
local  password 
)

Creates a new ZipArchive with the given path. If the password is defined, it

will be used to read encrypted archive. It won't affect the files added

to the archive.

Parameters
pathstring
passwordstring
Returns
lstg.ZipArchive

◆ createFromBuffer()

function createFromBuffer ( local  buffer,
local  mode,
local  checkConsistency 
)

Creates a new ZipArchive from the specified buffer. The archive will

directly be open with the given mode. If the archive fails to be open or

if the consistency check fails, this method will return null.

Parameters
bufferlstg.Buffer
modenumber
checkConsistencyboolean
Returns
lstg.ZipArchive

◆ deleteEntry()

function deleteEntry ( local  entry)

Deletes the specified entry from the zip file. If the entry is a folder, all its

subentries will be removed. This method returns the number of entries removed.

If the open mode does not allow a deletion, this method will return LIBZIPPP_ERROR_NOT_ALLOWED.

If the ZipArchive is not open, LIBZIPPP_ERROR_NOT_OPEN will be returned. If the entry is not handled

by this ZipArchive or is a null-ZipEntry, then LIBZIPPP_ERROR_INVALID_ENTRY will be returned.

If an error occurs during deletion, this method will return LIBZIPPP_ERROR_UNKNOWN.

If the entry does not exist, this method returns LIBZIPPP_ERROR_INVALID_PARAMETER.

Note that this method does not affect the result returned by getEntryCount !

Parameters
entrystring
Returns
boolean

◆ discard()

function discard ( )

Closes the ZipArchive and releases all the resources held by it. If the ZipArchive was

not open previously, this method does nothing. If the archive was open in modification

and some were done, they will be rollbacked.

Returns
lstg.ZipArchive

◆ extractEntry()

function extractEntry ( local  entry,
local  dstPath,
local  state 
)

Reads the specified entry of the ZipArchive and writes its content to

dstPath. If there is an error while reading the entry, then false will be returned.

The zip file must be opened otherwise null will be returned. If the entry was not

created by this ZipArchive, null will be returned. If the entry does not exist,

this method returns NULL:

Parameters
entrystring
dstPathstring
statenumber
Returns
boolean

◆ getComment()

function getComment ( )

Returns the comment of the archive. In order to set the comment, the archive

must have been open in WRITE or NEW mode. If the archive is not open, then

an empty string will be returned.

Returns
string

◆ getEntries()

function getEntries ( )

Returns all the entries of the ZipArchive. If the state is ORIGINAL, then

returns the entries in the original archive, any change will not be considered.

The zip file must be open otherwise an empty vector will be returned.

Returns
array_table

◆ getEntryByIndex()

function getEntryByIndex ( local  index,
local  state 
)

Returns the ZipEntry for the specified index. If the index is out of range,

then a null-ZipEntry will be returned.

The zip file must be open otherwise a null-ZipEntry will be returned.

Parameters
indexnumber
statenumber
Returns
string

◆ getEntryComment()

function getEntryComment ( local  entry,
local  state 
)

Returns the comment of the entry. If the ZipArchive is not open or the

entry is not linked to this archive, then an empty string will

be returned.

Parameters
entrystring
statenumber
Returns
string

◆ getEntryCount()

function getEntryCount ( )

Returns the number of entries in this zip file (folders are included).

The zip file must be open otherwise LIBZIPPP_ERROR_NOT_OPEN will be returned.

If the state is ORIGINAL, then the number entries of the original archive are returned.

Any change will not be considered.

Note also that the deleted entries does not affect the result of this method

with the CURRENT state. For instance, if there are 3 entries and you delete one,

this method will still return 3. However, if you add one entry, it will return

4 with the state CURRENT and 3 with the state ORIGINAL.

If you wanna know the "real" entries effectively in the archive, you might use

the getEntries method.

Returns
number

◆ getEntryInfo()

function getEntryInfo ( local  entry,
local  state 
)
Parameters
entrystring
statenumber
Returns
lstg.ZipArchive::ZipEntryInfo

◆ getMode()

function getMode ( )

Returns the mode in which the file has been open.

If the archive is not open, then NOT_OPEN will be returned.

Returns
number

◆ hasEntry()

function hasEntry ( local  entry,
local  excludeDirectories,
local  caseSensitive,
local  state 
)

Returns true if an entry with the specified name exists. If no such entry exists,

then false will be returned. If a directory is searched, the name must end with a '/' !

The zip file must be open otherwise false will be returned.

Parameters
entrystring
excludeDirectoriesboolean
caseSensitiveboolean
statenumber
Returns
boolean

◆ isEncrypted()

function isEncrypted ( )

Returns true if the ZipArchive is encrypted. This method returns true only if

a password has been set in the constructor.

Returns
boolean

◆ isEntryCompressionEnabled()

function isEntryCompressionEnabled ( local  entry,
local  state 
)

Returns the compression method of an entry. If the ZipArchive is not open

or the entry is not linked to this archive, false will be returned.

Parameters
entrystring
statenumber
Returns
boolean

◆ isMutable()

function isMutable ( )

Returns true if the ZipArchive is open and mutable.

Returns
boolean

◆ isOpen()

function isOpen ( )

Returns true if the ZipArchive is currently open.

Returns
boolean

◆ open()

function open ( local  mode,
local  checkConsistency 
)

Open the ZipArchive with the given mode. This method will return true if the operation

is successful, false otherwise. If the OpenMode is NOT_OPEN an invalid_argument

will be thrown. If the archive is already open, this method returns true only if the

mode is the same.

Parameters
modelstg.ZipArchive.OpenMode @optional
checkConsistencyboolean @optional
Returns
boolean

◆ readEntry()

function readEntry ( local  entry,
local  state 
)

Reads the specified ZipEntry of the ZipArchive and returns its content within

a char array. If there is an error while reading the entry, then null will be returned.

The data must be deleted by the developer once not used anymore.

The zip file must be open otherwise null will be returned. If the ZipEntry was not

created by this ZipArchive, null will be returned. If the zipEntry does not exist,

this method returns NULL:

Parameters
entrystring
statenumber
Returns
lstg.Buffer

◆ removeComment()

function removeComment ( )

Removes the comment of the archive, if any. The archive must have been open

in WRITE or NEW mode.

Returns
boolean

◆ renameEntry()

function renameEntry ( local  entry,
local  newName 
)

Renames the entry with the specified newName. The method returns the number of entries

that have been renamed, LIBZIPPP_ERROR_INVALID_PARAMETER if the new name is invalid,

LIBZIPPP_ERROR_NOT_ALLOWED if the mode doesn't allow modification or LIBZIPPP_ERROR_UNKNOWN if an error

occurred. If the entry is a directory, a '/' will automatically be appended at the end of newName if the

latter hasn't it already. All the files in the folder will be moved.

If the ZipArchive is not open or the entry was not edited by this ZipArchive or is a null-ZipEntry,

then LIBZIPPP_ERROR_INVALID_ENTRY will be returned. If the entry does not exist, this method returns LIBZIPPP_ERROR_INVALID_PARAMETER.

Parameters
entrystring
newNamestring
Returns
boolean

◆ setComment()

function setComment ( local  comment)

Defines the comment of the archive. In order to set the comment, the archive

must have been open in WRITE or NEW mode. If the archive is not open, then

false will be returned.

Parameters
commentstring
Returns
boolean

◆ setEntryComment()

function setEntryComment ( local  entry,
local  comment,
local  state 
)

Defines the comment of the entry. If the ZipArchive is not open or the

entry is not linked to this archive, then false will be returned.

Parameters
entrystring
commentstring
statenumber
Returns
boolean

◆ setEntryCompressionEnabled()

function setEntryCompressionEnabled ( local  entry,
local  value,
local  state 
)

Defines the compression method of an entry. If the ZipArchive is not open

or the entry is not linked to this archive, false will be returned.

Parameters
entrystring
valueboolean
statenumber
Returns
boolean

◆ unlink()

function unlink ( )

Deletes the file denoted by the path. If the ZipArchive is open, all the changes will

be discarded and the file removed.

Returns
boolean

The documentation for this class was generated from the following file: