Classes | Public Member Functions

ZipFile Class Reference

Decodes a ZIP file from a stream. More...

List of all members.

Classes

class  Builder
 Used to create a new zip file. More...
struct  ZipEntry
 Contains information about one of the entries in a ZipFile. More...

Public Member Functions

 ZipFile (InputStream *inputStream, bool deleteStreamWhenDestroyed)
 Creates a ZipFile for a given stream.
 ZipFile (const File &file)
 Creates a ZipFile based for a file.
 ZipFile (InputSource *inputSource)
 Creates a ZipFile for an input source.
 ~ZipFile ()
 Destructor.
int getNumEntries () const noexcept
 Returns the number of items in the zip file.
const ZipEntrygetEntry (int index) const noexcept
 Returns a structure that describes one of the entries in the zip file.
int getIndexOfFileName (const String &fileName) const noexcept
 Returns the index of the first entry with a given filename.
const ZipEntrygetEntry (const String &fileName) const noexcept
 Returns a structure that describes one of the entries in the zip file.
void sortEntriesByFilename ()
 Sorts the list of entries, based on the filename.
InputStreamcreateStreamForEntry (int index)
 Creates a stream that can read from one of the zip file's entries.
InputStreamcreateStreamForEntry (ZipEntry &entry)
 Creates a stream that can read from one of the zip file's entries.
bool uncompressTo (const File &targetDirectory, bool shouldOverwriteFiles=true)
 Uncompresses all of the files in the zip file.
bool uncompressEntry (int index, const File &targetDirectory, bool shouldOverwriteFiles=true)
 Uncompresses one of the entries from the zip file.

Detailed Description

Decodes a ZIP file from a stream.

This can enumerate the items in a ZIP file and can create suitable stream objects to read each one.


Constructor & Destructor Documentation

ZipFile::ZipFile ( InputStream inputStream,
bool  deleteStreamWhenDestroyed 
)

Creates a ZipFile for a given stream.

Parameters:
inputStreamthe stream to read from
deleteStreamWhenDestroyedif set to true, the object passed-in will be deleted when this ZipFile object is deleted
ZipFile::ZipFile ( const File file )

Creates a ZipFile based for a file.

ZipFile::ZipFile ( InputSource inputSource )

Creates a ZipFile for an input source.

The inputSource object will be owned by the zip file, which will delete it later when not needed.

ZipFile::~ZipFile (  )

Destructor.


Member Function Documentation

int ZipFile::getNumEntries (  ) const

Returns the number of items in the zip file.

const ZipEntry* ZipFile::getEntry ( int  index ) const

Returns a structure that describes one of the entries in the zip file.

This may return zero if the index is out of range.

See also:
ZipFile::ZipEntry
int ZipFile::getIndexOfFileName ( const String fileName ) const

Returns the index of the first entry with a given filename.

This uses a case-sensitive comparison to look for a filename in the list of entries. It might return -1 if no match is found.

See also:
ZipFile::ZipEntry
const ZipEntry* ZipFile::getEntry ( const String fileName ) const

Returns a structure that describes one of the entries in the zip file.

This uses a case-sensitive comparison to look for a filename in the list of entries. It might return 0 if no match is found.

See also:
ZipFile::ZipEntry
void ZipFile::sortEntriesByFilename (  )

Sorts the list of entries, based on the filename.

InputStream* ZipFile::createStreamForEntry ( int  index )

Creates a stream that can read from one of the zip file's entries.

The stream that is returned must be deleted by the caller (and zero might be returned if a stream can't be opened for some reason).

The stream must not be used after the ZipFile object that created has been deleted.

InputStream* ZipFile::createStreamForEntry ( ZipEntry entry )

Creates a stream that can read from one of the zip file's entries.

The stream that is returned must be deleted by the caller (and zero might be returned if a stream can't be opened for some reason).

The stream must not be used after the ZipFile object that created has been deleted.

bool ZipFile::uncompressTo ( const File targetDirectory,
bool  shouldOverwriteFiles = true 
)

Uncompresses all of the files in the zip file.

This will expand all the entries into a target directory. The relative paths of the entries are used.

Parameters:
targetDirectorythe root folder to uncompress to
shouldOverwriteFileswhether to overwrite existing files with similarly-named ones
Returns:
true if all the files are successfully unzipped
bool ZipFile::uncompressEntry ( int  index,
const File targetDirectory,
bool  shouldOverwriteFiles = true 
)

Uncompresses one of the entries from the zip file.

This will expand the entry and write it in a target directory. The entry's path is used to determine which subfolder of the target should contain the new file.

Parameters:
indexthe index of the entry to uncompress
targetDirectorythe root folder to uncompress into
shouldOverwriteFileswhether to overwrite existing files with similarly-named ones
Returns:
true if the files is successfully unzipped

The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines