michael@0: /* nsJARInputStream.h michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsJARINPUTSTREAM_h__ michael@0: #define nsJARINPUTSTREAM_h__ michael@0: michael@0: #include "nsIInputStream.h" michael@0: #include "nsJAR.h" michael@0: #include "nsTArray.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: /*------------------------------------------------------------------------- michael@0: * Class nsJARInputStream declaration. This class defines the type of the michael@0: * object returned by calls to nsJAR::GetInputStream(filename) for the michael@0: * purpose of reading a file item out of a JAR file. michael@0: *------------------------------------------------------------------------*/ michael@0: class nsJARInputStream MOZ_FINAL : public nsIInputStream michael@0: { michael@0: public: michael@0: nsJARInputStream() : michael@0: mOutSize(0), mInCrc(0), mOutCrc(0), mCurPos(0), michael@0: mMode(MODE_NOTINITED) michael@0: { michael@0: memset(&mZs, 0, sizeof(z_stream)); michael@0: } michael@0: michael@0: ~nsJARInputStream() { Close(); } michael@0: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIINPUTSTREAM michael@0: michael@0: // takes ownership of |fd|, even on failure michael@0: nsresult InitFile(nsJAR *aJar, nsZipItem *item); michael@0: michael@0: nsresult InitDirectory(nsJAR *aJar, michael@0: const nsACString& aJarDirSpec, michael@0: const char* aDir); michael@0: michael@0: private: michael@0: nsRefPtr mFd; // handle for reading michael@0: uint32_t mOutSize; // inflated size michael@0: uint32_t mInCrc; // CRC as provided by the zipentry michael@0: uint32_t mOutCrc; // CRC as calculated by me michael@0: z_stream mZs; // zip data structure michael@0: michael@0: /* For directory reading */ michael@0: nsRefPtr mJar; // string reference to zipreader michael@0: uint32_t mNameLen; // length of dirname michael@0: nsCString mBuffer; // storage for generated text of stream michael@0: uint32_t mCurPos; // Current position in buffer michael@0: uint32_t mArrPos; // current position within mArray michael@0: nsTArray mArray; // array of names in (zip) directory michael@0: michael@0: typedef enum { michael@0: MODE_NOTINITED, michael@0: MODE_CLOSED, michael@0: MODE_DIRECTORY, michael@0: MODE_INFLATE, michael@0: MODE_COPY michael@0: } JISMode; michael@0: michael@0: JISMode mMode; // Modus of the stream michael@0: michael@0: nsresult ContinueInflate(char* aBuf, uint32_t aCount, uint32_t* aBytesRead); michael@0: nsresult ReadDirectory(char* aBuf, uint32_t aCount, uint32_t* aBytesRead); michael@0: uint32_t CopyDataToBuffer(char* &aBuffer, uint32_t &aCount); michael@0: }; michael@0: michael@0: #endif /* nsJARINPUTSTREAM_h__ */ michael@0: