Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef ZippedFile_INCLUDE_ONCE
00033 #define ZippedFile_INCLUDE_ONCE
00034
00035 #include <vlCore/VirtualFile.hpp>
00036 struct z_stream_s;
00037
00038 namespace vl
00039 {
00040
00041
00042
00046 class ZippedFileInfo: public Object
00047 {
00048 friend class ZippedFile;
00049 friend class ZippedDirectory;
00050
00051 VL_INSTRUMENT_CLASS(vl::ZippedFileInfo, Object)
00052
00053 public:
00054 ZippedFileInfo()
00055 {
00056 mVersionNeeded = 0;
00057 mGeneralPurposeFlag = 0;
00058 mCompressionMethod = 0;
00059 mCRC32 = 0;
00060 mCompressedSize = 0;
00061 mUncompressedSize = 0;
00062 mFileNameLength = 0;
00063 mExtraFieldLength = 0;
00064 mSecond = 0;
00065 mMinute = 0;
00066 mHour = 0;
00067 mDay = 0;
00068 mMonth = 0;
00069 mYear = 0;
00070 mZippedFileOffset = 0;
00071 }
00072
00073 public:
00074 unsigned short versionNeeded() const { return mVersionNeeded; }
00075 unsigned short generalPurposeFlag() const { return mGeneralPurposeFlag; }
00076 unsigned short compressionMethod() const { return mCompressionMethod; }
00077 unsigned int crc32() const { return mCRC32; }
00078 unsigned int compressedSize() const { return mCompressedSize; }
00079 unsigned int uncompressedSize() const { return mUncompressedSize; }
00080 unsigned short fileNameLength() const { return mFileNameLength; }
00081 unsigned short extraFieldLength() const { return mExtraFieldLength; }
00082 int second() const { return mSecond; }
00083 int minute() const { return mMinute; }
00084 int hour() const { return mHour; }
00085 int day() const { return mDay; }
00086 int month() const { return mMonth; }
00087 int year() const { return mYear; }
00088 const String& path() const { return mFileName; }
00089
00090 unsigned int zippedFileOffset() const { return mZippedFileOffset; }
00091
00092 const VirtualFile* sourceZipFile() const { return mSourceZipFile.get(); }
00093 VirtualFile* sourceZipFile() { return mSourceZipFile.get(); }
00094 void setSourceZipFile(VirtualFile* file) { mSourceZipFile = file; }
00095
00096 public:
00097 unsigned short mVersionNeeded;
00098 unsigned short mGeneralPurposeFlag;
00099 unsigned short mCompressionMethod;
00100 unsigned int mCRC32;
00101 unsigned int mCompressedSize;
00102 unsigned int mUncompressedSize;
00103 unsigned short mFileNameLength;
00104 unsigned short mExtraFieldLength;
00105 int mSecond;
00106 int mMinute;
00107 int mHour;
00108 int mDay;
00109 int mMonth;
00110 int mYear;
00111 String mFileName;
00112
00113 unsigned int mZippedFileOffset;
00114
00115 ref<VirtualFile> mSourceZipFile;
00116 };
00117
00118
00119
00133 class VLCORE_EXPORT ZippedFile: public VirtualFile
00134 {
00135 VL_INSTRUMENT_CLASS(vl::ZippedFile, VirtualFile)
00136
00137
00138 static const int CHUNK_SIZE = 128*1024;
00139
00140 public:
00141
00142 ZippedFile();
00143 ~ZippedFile();
00144
00145 const ZippedFileInfo* zippedFileInfo() const;
00146
00147 ZippedFileInfo* zippedFileInfo();
00148
00149 void setZippedFileInfo(ZippedFileInfo* info);
00150
00153 virtual bool exists() const;
00154
00155 virtual bool open(EOpenMode mode);
00156
00157 virtual bool isOpen() const;
00158
00159 virtual void close();
00160
00161 virtual long long size() const;
00162
00163 bool extract(char* destination, bool check_sum = true);
00164
00165 ZippedFile& operator=(const ZippedFile& other)
00166 {
00167 close();
00168 super::operator=(other);
00169 mZippedFileInfo = new ZippedFileInfo(*other.mZippedFileInfo);
00170 if (mZippedFileInfo->sourceZipFile())
00171 {
00172 ref<VirtualFile> src_zip_copy = mZippedFileInfo->sourceZipFile()->clone();
00173 mZippedFileInfo->setSourceZipFile(src_zip_copy.get());
00174 }
00175 return *this;
00176 }
00177
00178 virtual ref<VirtualFile> clone() const;
00179
00180 void resetStream();
00181
00182 protected:
00183 virtual long long read_Implementation(void* buffer, long long bytes_to_read);
00184
00185 virtual long long write_Implementation(const void* , long long ) { return 0; }
00186
00187 virtual bool fillUncompressedBuffer();
00188
00189 virtual long long position_Implementation() const { return mReadBytes; }
00190
00191 virtual bool seekSet_Implementation(long long);
00192
00193 protected:
00194 ref<ZippedFileInfo> mZippedFileInfo;
00195 long long mReadBytes;
00196
00197 z_stream_s* mZStream;
00198 unsigned char mZipBufferIn[CHUNK_SIZE];
00199 unsigned char mZipBufferOut[CHUNK_SIZE];
00200 std::vector<char> mUncompressedBuffer;
00201 int mUncompressedBufferPtr;
00202 };
00203
00204
00205 bool compress(const void* data, size_t size, std::vector<unsigned char>& out, int level);
00206 bool decompress(const void* cdata, size_t csize, void* data_out);
00207
00208 }
00209
00210 #endif