Classes | Public Member Functions | List of all members
ZipFile Class Reference

A zip file on the local file system. More...

#include <ZipFile.hpp>

Inheritance diagram for ZipFile:
[legend]
Collaboration diagram for ZipFile:
[legend]

Classes

class  RecursiveZipFileIterator
 Recursive iterator into a zip file. More...
 
class  ZipFileIterator
 Non-recursive iterator into a zip file. More...
 

Public Member Functions

 ZipFile (File file_, std::string password_="")
 Create a new zip file for the specified file. More...
 
 ZipFile (const ZipFile &zipFile)=default
 Create a new zip file by copying the supplied instance. More...
 
 ZipFile (ZipFile &&zipFile) noexcept
 Create a new zip file by moving the contents of the supplied instance. More...
 
std::unique_ptr< Uriappend (const std::string &pathComponent) const override
 Appends the path component to the supplied URI, returning a new URI. More...
 
std::unique_ptr< ByteReadResourcebyteReadResource () const override
 Get a byte read resource for the URI. More...
 
std::unique_ptr< ByteWriteResourcebyteWriteResource () override
 Get a byte write resource for the URI. More...
 
bool canReadFrom () const override
 Can data be read from the URI via a read resource. More...
 
bool canWriteTo () const override
 Can data be written to the URI via a write resource. More...
 
std::unique_ptr< Uriclone () const override
 Clone the concrete Uri. More...
 
void dispatch (UriDispatcher &dispatcher) const override
 Visitor pattern dispatching. More...
 
FileIterator fileIterator () const override
 Get a non-recursive file iterator for this file (directory). More...
 
bool isIterable () const override
 Does the URI have a non-recursive iterator (examples: file and zip archive URIs). More...
 
bool isRecursivelyIterable () const override
 Does the URI have a recursive iterator (examples: file and zip archive URIs). More...
 
bool isRegularDirectory () const override
 Returns true if the file URI points to a directory. More...
 
bool isRegularFile () const override
 Returns true if the file URI points to a regular file. More...
 
std::unique_ptr< UriIteratoriterator () const override
 Get a (non-recursive) iterator. More...
 
ZipFileoperator= (const ZipFile &zipFile)=default
 Assign the zip file by copying the supplied instance. More...
 
ZipFileoperator= (ZipFile &&zipFile)=default
 Assign the zip file by moving the contents of the supplied instance. More...
 
bool operator== (const Uri &rhs) const override
 Compare the supplied URI to the current URI. More...
 
RecursiveFileIterator recursiveFileIterator () const override
 Get a recursive file iterator for this file (directory). More...
 
std::unique_ptr< RecursiveUriIteratorrecursiveIterator () const override
 Get a recursive iterator. More...
 
RecursiveZipFileIterator recursiveZipFileIterator (bool verify=false, const std::string &pw="")
 Get a recursive zip file iterator, specifying if the zip file should be verified and an optional encryption password. More...
 
std::unique_ptr< Uriresolve (std::string_view path) const override
 Resolve the relative or absolute path, in reference to the current URI. More...
 
std::unique_ptr< Utf32To8WriteResourceutf32To8WriteResource () override
 Get a UTF-32 to UTF-8 write resource for the URI. More...
 
std::unique_ptr< Utf8To32ReadResourceutf8To32ReadResource () const override
 Get a UTF-8 to UTF-32 read resource for the URI. More...
 
ZipFileIterator zipFileIterator (bool verify=false, const std::string &pw="")
 Get a non-recursive zip file iterator, specifying if the zip file should be verified and an optional encryption password. More...
 
- Public Member Functions inherited from File
 File ()=default
 Create an empty file URI. More...
 
 File (boost::filesystem::directory_entry entry_)
 Create a file from the supplied directory entry. More...
 
 File (const boost::filesystem::path &entry_)
 Create a file from the supplied Boost path. More...
 
 File (const std::string &path)
 Create a file path with the supplied path string. More...
 
 File (const char *path)
 Create a file path with the supplied path string. More...
 
 File (std::string_view path)
 Create a file path with the supplied path string. More...
 
 File (const std::string &path, const std::string &name)
 Create a file path with the supplied path string and filename string. More...
 
 File (const File &path, const std::string &name)
 Create a file path with the supplied path and filename. More...
 
 File (File &&file) noexcept
 Move an existing file URI into a new File URI. More...
 
 File (const File &file)
 Copy an existing file URI into a new File URI. More...
 
bool createDirectories () const
 Create all intermediate directories and the final directory. More...
 
bool exists () const
 Returns true if an item exits in the file system for the file URI. More...
 
FileByteReadResource getByteReadResource () const
 Get a file byte read resource for this file URI. More...
 
FileByteWriteResource getByteWriteResource () const
 Get a file byte write resource for this file URI. More...
 
File getChildEntry (std::string child) const
 
boost::filesystem::directory_entry getEntry () const
 Get the underlying directory entry for this file URI. More...
 
std::chrono::system_clock::time_point getModifiedTimestamp () const
 Get the modified time of the file. More...
 
File getParentDirectory () const
 Get the parent directory of the file URI. More...
 
File getSubDirectory (std::string subDirectory) const
 Create a new file representing the specified sub-directory of the file URI. More...
 
FileUtf32To8WriteResource getUtf32To8WriteResource () const
 Get a file UTF-8 to UTF-32 write resource for this file URI. More...
 
FileUtf8To32ReadResource getUtf8To32ReadResource () const
 Get a file UTF-8 to UTF-32 read resource for this file URI. More...
 
size_t hashcode () const noexcept override
 Get the URI's hash code. More...
 
File operator+ (const std::string &fragment) const
 Concatenate the supplied path fragment to the end of the path represented by the file. More...
 
File operator/ (const char *component) const
 Append a path component to the path represented by the file. More...
 
File operator/ (const std::string &component) const
 Append a path component to the path represented by the file. More...
 
File operator/ (const std::string_view &component) const
 Append a path component to the path represented by the file. More...
 
template<typename ... T, template< typename ... > class Container>
File operator/ (const Container< T ... > &container) const
 Append a sequence of path components to the path represented by the file. More...
 
Fileoperator/= (const char *component)
 Append a path component to the path represented by the file in place. More...
 
Fileoperator/= (const std::string &component)
 Append a path component to the path represented by the file in place. More...
 
Fileoperator/= (const std::string_view &component)
 Append a path component to the path represented by the file in place. More...
 
bool operator< (const File &rhs) const
 Return true if the current object is less than the supplied instance. More...
 
Fileoperator= (const File &file)
 Copy assign the supplied file to this file. More...
 
Fileoperator= (File &&file) noexcept
 Move assign the supplied file to this file. More...
 
Fileoperator= (const boost::filesystem::directory_entry &entry_)
 Copy the supplied directory entry to this file. More...
 
Fileoperator= (const boost::filesystem::path &path)
 Copy the supplied file system path to this file. More...
 
bool operator== (const File &rhs) const
 Compare the supplied file to the current file. More...
 
File relative (const File &base) const
 Get the relative path of the current object, compared to the supplied file. More...
 
bool removeFile () const
 Remove the file if it exists. More...
 
size_t size () const
 Get the size of the file if it exists or -1 if the file does not exist. More...
 
File toAbsolutePath () const
 Convert the file to an absolute path if it is relative, using the current working directory. More...
 
std::string toRawString () const override
 Get a string representing the raw URI. More...
 
template<typename AllocatorT >
Balau::U8String< AllocatorT > toRawString () const
 Get a string representing the raw URI. More...
 
std::string toUriString () const override
 Get a string representing the URI, complete with scheme. More...
 
- Public Member Functions inherited from Uri
virtual ~Uri ()=default
 Destroy the URI instance. More...
 
std::shared_ptr< UricloneToShared () const
 Clone the concrete Uri to a shared pointer. More...
 

Additional Inherited Members

- Static Public Attributes inherited from File
static const boost::filesystem::path::value_type separator = boost::filesystem::path::preferred_separator
 The path separator character for the platform. More...
 

Detailed Description

A zip file on the local file system.

Zip file iterators iterate over the zip entries in the zip file. From each zip entry, a read or write stream may be obtained to read from or modify the entry data.

If random read access is required over the entries of a zip file , it is better to use the Unzipper class directly instead of a ZipFile URI and iterator.

Constructor & Destructor Documentation

◆ ZipFile() [1/3]

ZipFile ( File  file_,
std::string  password_ = "" 
)
inlineexplicit

Create a new zip file for the specified file.

The caller is responsible for a path that points to a zip file when the ZipFile URI is subsequently used.

Parameters
file_the file URI pointing to the zip file
password_an optional encryption password for the zip file

◆ ZipFile() [2/3]

ZipFile ( const ZipFile zipFile)
default

Create a new zip file by copying the supplied instance.

◆ ZipFile() [3/3]

ZipFile ( ZipFile &&  zipFile)
inlinenoexcept

Create a new zip file by moving the contents of the supplied instance.

Member Function Documentation

◆ append()

std::unique_ptr<Uri> append ( const std::string &  pathComponent) const
inlineoverridevirtual

Appends the path component to the supplied URI, returning a new URI.

If the URI type does not permit appending of path components, UnsupportedOperationException is thrown.

Reimplemented from File.

◆ byteReadResource()

std::unique_ptr<ByteReadResource> byteReadResource ( ) const
inlineoverridevirtual

Get a byte read resource for the URI.

Exceptions
NotImplementedExceptionif the URI does not support reading
ResourceExceptionif the resource could not be created

Reimplemented from File.

◆ byteWriteResource()

std::unique_ptr<ByteWriteResource> byteWriteResource ( )
inlineoverridevirtual

Get a byte write resource for the URI.

Exceptions
NotImplementedExceptionif the URI does not support writing
ResourceExceptionif the resource could not be created

Reimplemented from File.

◆ canReadFrom()

bool canReadFrom ( ) const
inlineoverridevirtual

Can data be read from the URI via a read resource.

Reimplemented from File.

◆ canWriteTo()

bool canWriteTo ( ) const
inlineoverridevirtual

Can data be written to the URI via a write resource.

Reimplemented from File.

◆ clone()

std::unique_ptr<Uri> clone ( ) const
inlineoverridevirtual

Clone the concrete Uri.

Returns
a clone of the URI

Reimplemented from File.

◆ dispatch()

void dispatch ( UriDispatcher visitor) const
inlineoverridevirtual

Visitor pattern dispatching.

Parameters
visitorthe visitor to visit

Reimplemented from File.

◆ fileIterator()

FileIterator fileIterator ( ) const
inlineoverridevirtual

Get a non-recursive file iterator for this file (directory).

Returns
a file iterator
Exceptions
boost::filesystem::filesystem_errorif the current object is not a directory

Reimplemented from File.

◆ isIterable()

bool isIterable ( ) const
inlineoverridevirtual

Does the URI have a non-recursive iterator (examples: file and zip archive URIs).

Reimplemented from File.

◆ isRecursivelyIterable()

bool isRecursivelyIterable ( ) const
inlineoverridevirtual

Does the URI have a recursive iterator (examples: file and zip archive URIs).

Reimplemented from File.

◆ isRegularDirectory()

bool isRegularDirectory ( ) const
inlineoverridevirtual

Returns true if the file URI points to a directory.

Returns
true if the file URI points to a directory

Reimplemented from File.

◆ isRegularFile()

bool isRegularFile ( ) const
inlineoverridevirtual

Returns true if the file URI points to a regular file.

Returns
true if the file URI points to a regular file

Reimplemented from File.

◆ iterator()

std::unique_ptr<UriIterator> iterator ( ) const
inlineoverridevirtual

Get a (non-recursive) iterator.

This will throw a NotImplementedException if the URI does not have an iterator.

Reimplemented from File.

◆ operator=() [1/2]

ZipFile& operator= ( const ZipFile zipFile)
default

Assign the zip file by copying the supplied instance.

◆ operator=() [2/2]

ZipFile& operator= ( ZipFile &&  zipFile)
default

Assign the zip file by moving the contents of the supplied instance.

◆ operator==()

bool operator== ( const Uri rhs) const
inlineoverridevirtual

Compare the supplied URI to the current URI.

Returns
true if the supplied URI is equal to the current URI.

Reimplemented from File.

◆ recursiveFileIterator()

RecursiveFileIterator recursiveFileIterator ( ) const
inlineoverridevirtual

Get a recursive file iterator for this file (directory).

Returns
a recursive file iterator
Exceptions
boost::filesystem::filesystem_errorif the current object is not a directory

Reimplemented from File.

◆ recursiveIterator()

std::unique_ptr<RecursiveUriIterator> recursiveIterator ( ) const
inlineoverridevirtual

Get a recursive iterator.

This will throw a NotImplementedException if the URI does not have a recursive iterator.

Reimplemented from File.

◆ recursiveZipFileIterator()

RecursiveZipFileIterator recursiveZipFileIterator ( bool  verify = false,
const std::string &  pw = "" 
)
inline

Get a recursive zip file iterator, specifying if the zip file should be verified and an optional encryption password.

Parameters
verifyif true, the archive should first be verified
pwthe archive's password if encryption was used when writing

◆ resolve()

std::unique_ptr<Uri> resolve ( std::string_view  path) const
inlineoverridevirtual

Resolve the relative or absolute path, in reference to the current URI.

If the supplied path contains a scheme prefix, the URI fromString function will be called to create a new unrelated URI instance.

This method will determine the base path to use by applying the following rules.

  • If the URI path ends with a forward slash (or is a directory for file URIs), the base path is the URI path.
  • Otherwise, the rightmost path element is stripped from the URI path to form the base path.
Parameters
patha relative or absolute path, or a full URI
Returns
a new URI

Reimplemented from File.

◆ utf32To8WriteResource()

std::unique_ptr<Utf32To8WriteResource> utf32To8WriteResource ( )
inlineoverridevirtual

Get a UTF-32 to UTF-8 write resource for the URI.

Exceptions
NotImplementedExceptionif the URI does not support writing
ResourceExceptionif the resource could not be created

Reimplemented from File.

◆ utf8To32ReadResource()

std::unique_ptr<Utf8To32ReadResource> utf8To32ReadResource ( ) const
inlineoverridevirtual

Get a UTF-8 to UTF-32 read resource for the URI.

Exceptions
NotImplementedExceptionif the URI does not support reading
ResourceExceptionif the resource could not be created

Reimplemented from File.

◆ zipFileIterator()

ZipFileIterator zipFileIterator ( bool  verify = false,
const std::string &  pw = "" 
)
inline

Get a non-recursive zip file iterator, specifying if the zip file should be verified and an optional encryption password.

Parameters
verifyif true, the archive should first be verified
pwthe archive's password if encryption was used when writing

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