CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Common/File/VFS/ZipFileReader.h
Views: 1401
#pragma once12#ifdef SHARED_LIBZIP3#include <zip.h>4#else5#include "ext/libzip/zip.h"6#endif78#include <mutex>9#include <set>10#include <string>1112#include "Common/File/VFS/VFS.h"13#include "Common/File/FileUtil.h"14#include "Common/File/Path.h"1516class ZipFileReader : public VFSBackend {17public:18static ZipFileReader *Create(const Path &zipFile, const char *inZipPath, bool logErrors = true);19~ZipFileReader();2021bool IsValid() const { return zip_file_ != nullptr; }2223// use delete[] on the returned value.24uint8_t *ReadFile(const char *path, size_t *size) override;2526VFSFileReference *GetFile(const char *path) override;27bool GetFileInfo(VFSFileReference *vfsReference, File::FileInfo *fileInfo) override;28void ReleaseFile(VFSFileReference *vfsReference) override;2930VFSOpenFile *OpenFileForRead(VFSFileReference *vfsReference, size_t *size) override;31void Rewind(VFSOpenFile *vfsOpenFile) override;32size_t Read(VFSOpenFile *vfsOpenFile, void *buffer, size_t length) override;33void CloseFile(VFSOpenFile *vfsOpenFile) override;3435bool GetFileListing(const char *path, std::vector<File::FileInfo> *listing, const char *filter) override;36bool GetFileInfo(const char *path, File::FileInfo *info) override;37std::string toString() const override {38return inZipPath_;39}4041private:42ZipFileReader(zip *zip_file, const std::string &inZipPath) : zip_file_(zip_file), inZipPath_(inZipPath) {}43// Path has to be either an empty string, or a string ending with a /.44bool GetZipListings(const std::string &path, std::set<std::string> &files, std::set<std::string> &directories);4546zip *zip_file_ = nullptr;47std::mutex lock_;48std::string inZipPath_;49};505152