Loading...
Searching...
No Matches
juce_ZipFile.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API ZipFile
{
public:
explicit ZipFile (const File& file);
//==============================================================================
ZipFile (InputStream* inputStream, bool deleteStreamWhenDestroyed);
explicit ZipFile (InputStream& inputStream);
explicit ZipFile (InputSource* inputSource);
~ZipFile();
//==============================================================================
struct ZipEntry
{
String filename;
int64 uncompressedSize;
Time fileTime;
bool isSymbolicLink;
uint32 externalFileAttributes;
};
//==============================================================================
int getNumEntries() const noexcept;
const ZipEntry* getEntry (int index) const noexcept;
int getIndexOfFileName (const String& fileName, bool ignoreCase = false) const noexcept;
const ZipEntry* getEntry (const String& fileName, bool ignoreCase = false) const noexcept;
void sortEntriesByFilename();
//==============================================================================
InputStream* createStreamForEntry (int index);
InputStream* createStreamForEntry (const ZipEntry& entry);
//==============================================================================
Result uncompressTo (const File& targetDirectory,
bool shouldOverwriteFiles = true);
Result uncompressEntry (int index,
const File& targetDirectory,
bool shouldOverwriteFiles = true);
enum class OverwriteFiles { no, yes };
enum class FollowSymlinks { no, yes };
Result uncompressEntry (int index,
const File& targetDirectory,
OverwriteFiles overwriteFiles,
FollowSymlinks followSymlinks);
//==============================================================================
class JUCE_API Builder
{
public:
Builder();
~Builder();
void addFile (const File& fileToAdd, int compressionLevel,
const String& storedPathName = String());
void addEntry (InputStream* streamToRead, int compressionLevel,
const String& storedPathName, Time fileModificationTime);
bool writeToStream (OutputStream& target, double* progress) const;
//==============================================================================
private:
struct Item;
OwnedArray<Item> items;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Builder)
};
private:
//==============================================================================
struct ZipInputStream;
struct ZipEntryHolder;
OwnedArray<ZipEntryHolder> entries;
CriticalSection lock;
InputStream* inputStream = nullptr;
std::unique_ptr<InputStream> streamToDelete;
std::unique_ptr<InputSource> inputSource;
#if JUCE_DEBUG
struct OpenStreamCounter
{
OpenStreamCounter() = default;
~OpenStreamCounter();
int numOpenStreams = 0;
};
OpenStreamCounter streamCounter;
#endif
void init();
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ZipFile)
};
} // namespace juce
juce::CriticalSection
Definition juce_CriticalSection.h:43
juce::File
Definition juce_File.h:45
juce::InputSource
Definition juce_InputSource.h:38
juce::InputStream
Definition juce_InputStream.h:37
juce::OutputStream
Definition juce_OutputStream.h:38
juce::OwnedArray
Definition juce_OwnedArray.h:50
juce::Result
Definition juce_Result.h:57
juce::String
Definition juce_String.h:53
juce::Time
Definition juce_Time.h:37
juce::ZipFile::Builder::Builder
Builder()
Definition juce_ZipFile.cpp:615
juce::ZipFile::Builder::addEntry
void addEntry(InputStream *streamToRead, int compressionLevel, const String &storedPathName, Time fileModificationTime)
Definition juce_ZipFile.cpp:625
juce::ZipFile::Builder::writeToStream
bool writeToStream(OutputStream &target, double *progress) const
Definition juce_ZipFile.cpp:632
juce::ZipFile::Builder::addFile
void addFile(const File &fileToAdd, int compressionLevel, const String &storedPathName=String())
Definition juce_ZipFile.cpp:618
juce::ZipFile
Definition juce_ZipFile.h:36
juce::ZipFile::uncompressTo
Result uncompressTo(const File &targetDirectory, bool shouldOverwriteFiles=true)
Definition juce_ZipFile.cpp:401
juce::ZipFile::createStreamForEntry
InputStream * createStreamForEntry(int index)
Definition juce_ZipFile.cpp:314
juce::ZipFile::getEntry
const ZipEntry * getEntry(int index) const noexcept
Definition juce_ZipFile.cpp:287
juce::ZipFile::getNumEntries
int getNumEntries() const noexcept
Definition juce_ZipFile.cpp:282
juce::ZipFile::ZipEntry::filename
String filename
Definition juce_ZipFile.h:75
juce::ZipFile::ZipEntry::uncompressedSize
int64 uncompressedSize
Definition juce_ZipFile.h:78
juce::ZipFile::ZipFile
ZipFile(const File &file)
Definition juce_ZipFile.cpp:254
juce::ZipFile::ZipEntry::externalFileAttributes
uint32 externalFileAttributes
Definition juce_ZipFile.h:90
juce::ZipFile::ZipEntry::isSymbolicLink
bool isSymbolicLink
Definition juce_ZipFile.h:84
juce::ZipFile::uncompressEntry
Result uncompressEntry(int index, const File &targetDirectory, bool shouldOverwriteFiles=true)
Definition juce_ZipFile.cpp:415
juce::ZipFile::getIndexOfFileName
int getIndexOfFileName(const String &fileName, bool ignoreCase=false) const noexcept
Definition juce_ZipFile.cpp:295
juce::ZipFile::sortEntriesByFilename
void sortEntriesByFilename()
Definition juce_ZipFile.cpp:345
juce::ZipFile::ZipEntry::fileTime
Time fileTime
Definition juce_ZipFile.h:81
juce::ZipFile::ZipEntry
Definition juce_ZipFile.h:73