#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2013 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_STORAGE_FILESYSTEM_ZIP_ZIPPEDFILE_H #define NUCLEX_STORAGE_FILESYSTEM_ZIP_ZIPPEDFILE_H #include "Nuclex/Storage/Config.h" #include "Nuclex/Storage/FileSystem/File.h" #include "Format/CompressionMethod.h" #include namespace Nuclex { namespace Storage { namespace FileSystem { namespace Zip { // ------------------------------------------------------------------------------------------- // class ZipArchiveContainer; class ZipReader; // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Storage::FileSystem::Zip namespace Nuclex { namespace Storage { namespace FileSystem { namespace Zip { // ------------------------------------------------------------------------------------------- // /// File stored in a zip archive class ZippedFile : public File { #pragma region struct MetaData /// Data about the compressed file public: struct MetaData { /// Full path of the file in the native system public: std::string NativePath; /// Name of the file public: std::string Filename; /// Offset of the compressed data within the zip archive public: std::uint64_t CompressedDataOffset; /// Length of the file in compressed form public: std::uint64_t CompressedSize; /// Length of the file when it is uncompressed public: std::uint64_t UncompressedSize; /// Compression method used to compress the file's contents public: CompressionMethod::Enum CompressionMethod; /// Time at which the file was last modified public: std::time_t LastModificationTime; }; #pragma endregion // struct MetaData /// Initializes a new file stored in a zip archive /// Cached reader for the file's contents /// Data describing the compressed file public: ZippedFile( const std::shared_ptr &zipReader, const MetaData &metaData ); /// Frees all resources owned by the instance public: virtual ~ZippedFile(); /// Determines the size of the file /// The size of the file in bytes public: std::uint64_t GetSize() const { return this->metaData.UncompressedSize; } /// Returns the name of the file /// The file's name public: const std::string &GetName() const { return this->metaData.Filename; } /// Changes the name of the file /// New name the file will be known under public: void SetName(const std::string &name); /// Returns the path the file is stored at in the native format /// The file's absolute path in the native OS format public: const std::string &GetNativePath() const { return this->metaData.NativePath; } /// Retrieves the time at which the file has been last modified /// The since since the last modification of the file took place public: std::time_t GetLastModificationTime() const { return this->metaData.LastModificationTime; } /// Reads raw data from the file /// Absolute file position data will be read from /// Buffer into which data will be read /// Number of bytes that will be read public: void ReadAt( std::uint64_t location, void *buffer, std::size_t count ) const; /// Writes raw data into the file /// Absolute file position data will be written to /// Buffer from which data will be taken /// Number of bytes that will be written public: void WriteAt( std::uint64_t location, const void *buffer, std::size_t count ); /// Ensures changes to the file have been written to disk public: void Flush() { // Since writing isn't supported, there's nothing to do here. } private: ZippedFile(const ZippedFile &); private: ZippedFile &operator =(const ZippedFile &); /// Decompresses data from the zip archive private: std::shared_ptr zipReader; /// Describing informations about the compressed file private: MetaData metaData; }; // ------------------------------------------------------------------------------------------- // }}}} // namespace Nuclex::Storage::FileSystem::Zip #endif // NUCLEX_STORAGE_FILESYSTEM_ZIP_ZIPPEDFILE_H