class EE::System::Zip

Overview

ZIP archive reader/writer and optional resource pack. More…

#include <zip.hpp>

class Zip: public EE::System::Pack {
public:
    // enums

    enum Error;
    enum OpenMode;

    // structs

    struct Entry;

    // construction

    Zip();
    Zip(bool registerResource);
    ~Zip();

    // methods

    static Zip* New();
    virtual bool create(const std::string& path);
    virtual bool open(const std::string& path);
    bool open(const std::string& path, OpenMode mode);
    Uint64 entryCount() const;
    Uint64 metadataSize() const;
    bool entry(Uint64 index, Entry& result);
    std::unique_ptr<IOStream> openStream(Uint64 index);
    Error error() const;
    const std::string& errorMessage() const;
    virtual bool close();
    virtual bool addFile(const std::string& path, const std::string& inpack);
    virtual bool addFile(const Uint8* data, const Uint32& dataSize, const std::string& inpack);
    virtual bool addFiles(std::map<std::string, std::string> paths);
    virtual bool eraseFile(const std::string& path);
    virtual bool eraseFiles(const std::vector<std::string>& paths);
    virtual bool extractFile(const std::string& path, const std::string& dest);
    virtual bool extractFileToMemory(const std::string& path, std::vector<Uint8>& data);
    virtual bool extractFileToMemory(const std::string& path, ScopedBuffer& data);
    virtual Int32 exists(const std::string& path);
    virtual Int8 checkPack();
    virtual std::vector<std::string> getFileList();
    virtual bool addFile(std::vector<Uint8>& data, const std::string& inpack);
    virtual std::string getPackPath();
    virtual IOStream* getFileStream(const std::string& path);
};

Inherited Members

public:
    // methods

    void lock();
    void unlock();
    bool tryLock();
    virtual bool create(const std::string& path) = 0;
    virtual bool open(const std::string& path) = 0;
    virtual bool close() = 0;
    virtual bool addFile(const std::string& path, const std::string& inpack) = 0;
    virtual bool addFile(std::vector<Uint8>& data, const std::string& inpack) = 0;
    virtual bool addFile(const Uint8* data, const Uint32& dataSize, const std::string& inpack) = 0;
    virtual bool addFiles(std::map<std::string, std::string> paths) = 0;
    virtual bool eraseFile(const std::string& path) = 0;
    virtual bool eraseFiles(const std::vector<std::string>& paths) = 0;
    virtual bool extractFile(const std::string& path, const std::string& dest) = 0;
    virtual bool extractFileToMemory(const std::string& path, std::vector<Uint8>& data) = 0;
    virtual bool extractFileToMemory(const std::string& path, ScopedBuffer& data) = 0;
    virtual Int32 exists(const std::string& path) = 0;
    virtual Int8 checkPack() = 0;
    virtual std::vector<std::string> getFileList() = 0;
    virtual bool isOpen() const;
    virtual std::string getPackPath() = 0;
    virtual IOStream* getFileStream(const std::string& path) = 0;

Detailed Documentation

ZIP archive reader/writer and optional resource pack. Use Zip(false) and OpenMode::ReadOnlyBounded for untrusted standalone browsing. Entry streams borrow the archive and must be destroyed before it. Serialize access to an archive and its streams when sharing them between threads.

Methods

virtual bool create(const std::string& path)

Creates a new pack file

virtual bool open(const std::string& path)

Opens an existing archive for reading and writing. Missing files are never created; use create() explicitly.

bool open(const std::string& path, OpenMode mode)

ReadOnly supports Unicode native paths and cannot modify or create an archive.

Uint64 metadataSize() const

Conservative decoded central-directory memory estimate, including allocation slack. This excludes decompressed file data and indexes built by the caller.

std::unique_ptr<IOStream> openStream(Uint64 index)

Opens an entry without extracting it into memory. Backward seeks replay the prefix; scratch space is bounded. Reads/seeks return -1 on error, including CRC failures.

virtual bool close()

Close the pack file

virtual bool addFile(const std::string& path, const std::string& inpack)

Add a file to the pack file

Parameters:

path

Path to the file in the disk

inpack

Path that will have the file inside the pak

Returns:

True if success

virtual bool addFile(const Uint8* data, const Uint32& dataSize, const std::string& inpack)

Add a new file from memory

virtual bool addFiles(std::map<std::string, std::string> paths)

Add a map of files to the pack file ( myMap[ myFilepath ] = myInPackFilepath )

virtual bool eraseFile(const std::string& path)

Erase a file from the pack file. ( This will create a new pack file without that file, so, can be slow )

virtual bool eraseFiles(const std::vector<std::string>& paths)

Erase all passed files from the pack file. ( This will create a new pack file without that file, so, can be slow )

virtual bool extractFile(const std::string& path, const std::string& dest)

Extract a file from the pack file

virtual bool extractFileToMemory(const std::string& path, std::vector<Uint8>& data)

Extract a file to memory from the pack file

virtual bool extractFileToMemory(const std::string& path, ScopedBuffer& data)

Extract a file to memory from the pakFile

virtual Int32 exists(const std::string& path)

Check if a file exists in the pack file and return the number of the file, otherwise return -1.

virtual Int8 checkPack()

Check the integrity of the pack file.

If return 0 integrity OK. -1 wrong identifier. -2 wrong header.

virtual std::vector<std::string> getFileList()

Returns:

a vector with all the files inside the pack file

virtual bool addFile(std::vector<Uint8>& data, const std::string& inpack)

Add a new file from memory

virtual std::string getPackPath()

Returns:

The file path of the opened package

virtual IOStream* getFileStream(const std::string& path)

Open a file stream for reading