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

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

mercurial