1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/modules/libjar/nsJARInputStream.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,73 @@ 1.4 +/* nsJARInputStream.h 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef nsJARINPUTSTREAM_h__ 1.11 +#define nsJARINPUTSTREAM_h__ 1.12 + 1.13 +#include "nsIInputStream.h" 1.14 +#include "nsJAR.h" 1.15 +#include "nsTArray.h" 1.16 +#include "mozilla/Attributes.h" 1.17 + 1.18 +/*------------------------------------------------------------------------- 1.19 + * Class nsJARInputStream declaration. This class defines the type of the 1.20 + * object returned by calls to nsJAR::GetInputStream(filename) for the 1.21 + * purpose of reading a file item out of a JAR file. 1.22 + *------------------------------------------------------------------------*/ 1.23 +class nsJARInputStream MOZ_FINAL : public nsIInputStream 1.24 +{ 1.25 + public: 1.26 + nsJARInputStream() : 1.27 + mOutSize(0), mInCrc(0), mOutCrc(0), mCurPos(0), 1.28 + mMode(MODE_NOTINITED) 1.29 + { 1.30 + memset(&mZs, 0, sizeof(z_stream)); 1.31 + } 1.32 + 1.33 + ~nsJARInputStream() { Close(); } 1.34 + 1.35 + NS_DECL_THREADSAFE_ISUPPORTS 1.36 + NS_DECL_NSIINPUTSTREAM 1.37 + 1.38 + // takes ownership of |fd|, even on failure 1.39 + nsresult InitFile(nsJAR *aJar, nsZipItem *item); 1.40 + 1.41 + nsresult InitDirectory(nsJAR *aJar, 1.42 + const nsACString& aJarDirSpec, 1.43 + const char* aDir); 1.44 + 1.45 + private: 1.46 + nsRefPtr<nsZipHandle> mFd; // handle for reading 1.47 + uint32_t mOutSize; // inflated size 1.48 + uint32_t mInCrc; // CRC as provided by the zipentry 1.49 + uint32_t mOutCrc; // CRC as calculated by me 1.50 + z_stream mZs; // zip data structure 1.51 + 1.52 + /* For directory reading */ 1.53 + nsRefPtr<nsJAR> mJar; // string reference to zipreader 1.54 + uint32_t mNameLen; // length of dirname 1.55 + nsCString mBuffer; // storage for generated text of stream 1.56 + uint32_t mCurPos; // Current position in buffer 1.57 + uint32_t mArrPos; // current position within mArray 1.58 + nsTArray<nsCString> mArray; // array of names in (zip) directory 1.59 + 1.60 + typedef enum { 1.61 + MODE_NOTINITED, 1.62 + MODE_CLOSED, 1.63 + MODE_DIRECTORY, 1.64 + MODE_INFLATE, 1.65 + MODE_COPY 1.66 + } JISMode; 1.67 + 1.68 + JISMode mMode; // Modus of the stream 1.69 + 1.70 + nsresult ContinueInflate(char* aBuf, uint32_t aCount, uint32_t* aBytesRead); 1.71 + nsresult ReadDirectory(char* aBuf, uint32_t aCount, uint32_t* aBytesRead); 1.72 + uint32_t CopyDataToBuffer(char* &aBuffer, uint32_t &aCount); 1.73 +}; 1.74 + 1.75 +#endif /* nsJARINPUTSTREAM_h__ */ 1.76 +