tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsJARInputStream.h (2374B)


      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/. */
      6 
      7 #ifndef nsJARINPUTSTREAM_h__
      8 #define nsJARINPUTSTREAM_h__
      9 
     10 #include "nsIInputStream.h"
     11 #include "nsJAR.h"
     12 #include "nsTArray.h"
     13 
     14 /*-------------------------------------------------------------------------
     15 * Class nsJARInputStream declaration. This class defines the type of the
     16 * object returned by calls to nsJAR::GetInputStream(filename) for the
     17 * purpose of reading a file item out of a JAR file.
     18 *------------------------------------------------------------------------*/
     19 class nsJARInputStream final : public nsIInputStream {
     20 public:
     21  nsJARInputStream()
     22      : mOutSize(0),
     23        mInCrc(0),
     24        mOutCrc(0),
     25        mNameLen(0),
     26        mCurPos(0),
     27        mArrPos(0),
     28        mMode(MODE_NOTINITED) {
     29    memset(&mZs, 0, sizeof(z_stream));
     30  }
     31 
     32  NS_DECL_THREADSAFE_ISUPPORTS
     33  NS_DECL_NSIINPUTSTREAM
     34 
     35  // takes ownership of |fd|, even on failure
     36  nsresult InitFile(nsZipHandle* aFd, const uint8_t* aData, nsZipItem* item);
     37 
     38  nsresult InitDirectory(nsJAR* aJar, const char* aDir);
     39 
     40 private:
     41  ~nsJARInputStream() { Close(); }
     42 
     43  RefPtr<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
     48 
     49  /* For directory reading */
     50  RefPtr<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
     56 
     57  typedef enum {
     58    MODE_NOTINITED,
     59    MODE_CLOSED,
     60    MODE_DIRECTORY,
     61    MODE_INFLATE,
     62    MODE_COPY
     63  } JISMode;
     64 
     65  JISMode mMode;  // Modus of the stream
     66 
     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 };
     71 
     72 #endif /* nsJARINPUTSTREAM_h__ */