Loading...
Searching...
No Matches
juce::ZipFile Class Reference

## 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.

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

- juce_core/zip/juce_ZipFile.h

## Classes

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

## Public Types

enum class | OverwriteFiles { no , yes }
enum class | FollowSymlinks { no , yes }

## Public Member Functions

| ZipFile (const File &file)
| Creates a ZipFile to read a specific file.
| ZipFile (std::unique_ptr< InputStream > inputStream)
| Creates a ZipFile for the given stream.
| ZipFile (std::unique_ptr< InputSource > inputSource)
| Creates a ZipFile for the given input source.
| ZipFile (InputStream &inputStream)
| Creates a ZipFile for the given stream.
| ZipFile (InputStream *inputStream, bool deleteStreamWhenDestroyed)
| ZipFile (InputSource *inputSource)
| ~ZipFile ()
| Destructor.
int | getNumEntries () const noexcept
| Returns the number of items in the zip file.
const ZipEntry * | getEntry (int index) const noexcept
| Returns a structure that describes one of the entries in the zip file.
int | getIndexOfFileName (const String &fileName, bool ignoreCase=false) const noexcept
| Returns the index of the first entry with a given filename.
const ZipEntry * | getEntry (const String &fileName, bool ignoreCase=false) 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.
InputStream * | createStreamForEntry (int index)
| Creates a stream that can read from one of the zip file's entries.
InputStream * | createStreamForEntry (const ZipEntry &entry)
| Creates a stream that can read from one of the zip file's entries.
Result | uncompressTo (const File &targetDirectory, bool shouldOverwriteFiles=true)
| Uncompresses all of the files in the zip file.
Result | uncompressEntry (int index, const File &targetDirectory, bool shouldOverwriteFiles=true)
| Uncompresses one of the entries from the zip file.
Result | uncompressEntry (int index, const File &targetDirectory, OverwriteFiles overwriteFiles, FollowSymlinks followSymlinks)
| Uncompresses one of the entries from the zip file.

## Member Enums

## OverwriteFiles

enum class juce::ZipFile::OverwriteFiles

strong

Enumerator
no |
yes |

## FollowSymlinks

enum class juce::ZipFile::FollowSymlinks

strong

Enumerator
no |
yes |

## Constructors and Destructors

## ZipFile() [1/6]

juce::ZipFile::ZipFile | ( | const File & | file | ) |

explicit

Creates a ZipFile to read a specific file.

## ZipFile() [2/6]

juce::ZipFile::ZipFile | ( | std::unique_ptr< InputStream > | inputStream | ) |

explicit

Creates a ZipFile for the given stream.

## ZipFile() [3/6]

juce::ZipFile::ZipFile | ( | std::unique_ptr< InputSource > | inputSource | ) |

explicit

Creates a ZipFile for the given input source.

## ZipFile() [4/6]

juce::ZipFile::ZipFile | ( | InputStream & | inputStream | ) |

explicit

Creates a ZipFile for the given stream.

The stream will not be owned or deleted by this class - if you want the ZipFile to manage the stream's lifetime, use the constructor that takes a unique_ptr argument.

## ZipFile() [5/6]

juce::ZipFile::ZipFile | ( | InputStream * | inputStream,
|  | bool | deleteStreamWhenDestroyed )

Deprecated

Parameters

  inputStream | the stream to read from
  deleteStreamWhenDestroyed | if set to true, the object passed-in will be deleted when this ZipFile object is deleted

## ZipFile() [6/6]

juce::ZipFile::ZipFile | ( | InputSource * | inputSource | ) |

explicit

Deprecated

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

## ~ZipFile()

juce::ZipFile::~ZipFile | ( |  | ) |

Destructor.

## Member Functions

## getNumEntries()

int juce::ZipFile::getNumEntries | ( |  | ) | const

noexcept

Returns the number of items in the zip file.

## getEntry() [1/2]

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

noexcept

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

This may return a nullptr if the index is out of range.

See also
  ZipFile::ZipEntry

References getEntry().

Referenced by getEntry(), and getEntry().

## getIndexOfFileName()

int juce::ZipFile::getIndexOfFileName | ( | const String & | fileName,
|  | bool | ignoreCase = false ) const

noexcept

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

References getIndexOfFileName().

Referenced by getIndexOfFileName().

## getEntry() [2/2]

const ZipEntry * juce::ZipFile::getEntry | ( | const String & | fileName,
|  | bool | ignoreCase = false ) const

noexcept

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

References getEntry().

## sortEntriesByFilename()

void juce::ZipFile::sortEntriesByFilename | ( |  | ) |

Sorts the list of entries, based on the filename.

References sortEntriesByFilename().

Referenced by sortEntriesByFilename().

## createStreamForEntry() [1/2]

InputStream * juce::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 a nullptr 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.

Note that if the ZipFile was created with a user-supplied InputStream object, then all the streams which are created by this method will by trying to share the same source stream, so cannot be safely used on multiple threads! (But if you create the ZipFile from a File or InputSource, then it is safe to do this).

References createStreamForEntry().

Referenced by createStreamForEntry(), and createStreamForEntry().

## createStreamForEntry() [2/2]

InputStream * juce::ZipFile::createStreamForEntry | ( | const 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 a nullptr 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.

Note that if the ZipFile was created with a user-supplied InputStream object, then all the streams which are created by this method will by trying to share the same source stream, so cannot be safely used on multiple threads! (But if you create the ZipFile from a File or InputSource, then it is safe to do this).

References createStreamForEntry().

## uncompressTo()

Result juce::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

  targetDirectory | the root folder to uncompress to
  shouldOverwriteFiles | whether to overwrite existing files with similarly-named ones

Returns
  success if the file is successfully unzipped

References uncompressTo().

Referenced by uncompressTo().

## uncompressEntry() [1/2]

Result juce::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

  index | the index of the entry to uncompress - this must be a valid index between 0 and (getNumEntries() - 1).
  targetDirectory | the root folder to uncompress into
  shouldOverwriteFiles | whether to overwrite existing files with similarly-named ones

Returns
  success if all the files are successfully unzipped

References uncompressEntry().

Referenced by uncompressEntry().

## uncompressEntry() [2/2]

Result juce::ZipFile::uncompressEntry | ( | int | index,
|  | const File & | targetDirectory,
|  | OverwriteFiles | overwriteFiles,
|  | FollowSymlinks | followSymlinks )

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

  index | the index of the entry to uncompress - this must be a valid index between 0 and (getNumEntries() - 1).
  targetDirectory | the root folder to uncompress into
  overwriteFiles | whether to overwrite existing files with similarly-named ones
  followSymlinks | whether to follow symlinks inside the target directory

Returns
  success if all the files are successfully unzipped

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited