modules/libjar/nsJARInputStream.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* nsJARInputStream.h
michael@0 2 *
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef nsJARINPUTSTREAM_h__
michael@0 8 #define nsJARINPUTSTREAM_h__
michael@0 9
michael@0 10 #include "nsIInputStream.h"
michael@0 11 #include "nsJAR.h"
michael@0 12 #include "nsTArray.h"
michael@0 13 #include "mozilla/Attributes.h"
michael@0 14
michael@0 15 /*-------------------------------------------------------------------------
michael@0 16 * Class nsJARInputStream declaration. This class defines the type of the
michael@0 17 * object returned by calls to nsJAR::GetInputStream(filename) for the
michael@0 18 * purpose of reading a file item out of a JAR file.
michael@0 19 *------------------------------------------------------------------------*/
michael@0 20 class nsJARInputStream MOZ_FINAL : public nsIInputStream
michael@0 21 {
michael@0 22 public:
michael@0 23 nsJARInputStream() :
michael@0 24 mOutSize(0), mInCrc(0), mOutCrc(0), mCurPos(0),
michael@0 25 mMode(MODE_NOTINITED)
michael@0 26 {
michael@0 27 memset(&mZs, 0, sizeof(z_stream));
michael@0 28 }
michael@0 29
michael@0 30 ~nsJARInputStream() { Close(); }
michael@0 31
michael@0 32 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 33 NS_DECL_NSIINPUTSTREAM
michael@0 34
michael@0 35 // takes ownership of |fd|, even on failure
michael@0 36 nsresult InitFile(nsJAR *aJar, nsZipItem *item);
michael@0 37
michael@0 38 nsresult InitDirectory(nsJAR *aJar,
michael@0 39 const nsACString& aJarDirSpec,
michael@0 40 const char* aDir);
michael@0 41
michael@0 42 private:
michael@0 43 nsRefPtr<nsZipHandle> mFd; // handle for reading
michael@0 44 uint32_t mOutSize; // inflated size
michael@0 45 uint32_t mInCrc; // CRC as provided by the zipentry
michael@0 46 uint32_t mOutCrc; // CRC as calculated by me
michael@0 47 z_stream mZs; // zip data structure
michael@0 48
michael@0 49 /* For directory reading */
michael@0 50 nsRefPtr<nsJAR> mJar; // string reference to zipreader
michael@0 51 uint32_t mNameLen; // length of dirname
michael@0 52 nsCString mBuffer; // storage for generated text of stream
michael@0 53 uint32_t mCurPos; // Current position in buffer
michael@0 54 uint32_t mArrPos; // current position within mArray
michael@0 55 nsTArray<nsCString> mArray; // array of names in (zip) directory
michael@0 56
michael@0 57 typedef enum {
michael@0 58 MODE_NOTINITED,
michael@0 59 MODE_CLOSED,
michael@0 60 MODE_DIRECTORY,
michael@0 61 MODE_INFLATE,
michael@0 62 MODE_COPY
michael@0 63 } JISMode;
michael@0 64
michael@0 65 JISMode mMode; // Modus of the stream
michael@0 66
michael@0 67 nsresult ContinueInflate(char* aBuf, uint32_t aCount, uint32_t* aBytesRead);
michael@0 68 nsresult ReadDirectory(char* aBuf, uint32_t aCount, uint32_t* aBytesRead);
michael@0 69 uint32_t CopyDataToBuffer(char* &aBuffer, uint32_t &aCount);
michael@0 70 };
michael@0 71
michael@0 72 #endif /* nsJARINPUTSTREAM_h__ */
michael@0 73

mercurial