Bug 1803740 - Apply the minimum-scale for desktop mode. r=botond
[gecko.git] / modules / libjar / nsJARInputStream.h
blob69cbf605b6c2c24392d323d7098fff3fa43cb1e2
1 /* nsJARInputStream.h
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 final : public nsIInputStream {
21 public:
22 nsJARInputStream()
23 : mOutSize(0),
24 mInCrc(0),
25 mOutCrc(0),
26 mNameLen(0),
27 mCurPos(0),
28 mArrPos(0),
29 mMode(MODE_NOTINITED) {
30 memset(&mZs, 0, sizeof(z_stream));
33 NS_DECL_THREADSAFE_ISUPPORTS
34 NS_DECL_NSIINPUTSTREAM
36 // takes ownership of |fd|, even on failure
37 nsresult InitFile(nsZipHandle* aFd, const uint8_t* aData, nsZipItem* item);
39 nsresult InitDirectory(nsJAR* aJar, const nsACString& aJarDirSpec,
40 const char* aDir);
42 private:
43 ~nsJARInputStream() { Close(); }
45 RefPtr<nsZipHandle> mFd; // handle for reading
46 uint32_t mOutSize; // inflated size
47 uint32_t mInCrc; // CRC as provided by the zipentry
48 uint32_t mOutCrc; // CRC as calculated by me
49 z_stream mZs; // zip data structure
51 /* For directory reading */
52 RefPtr<nsJAR> mJar; // string reference to zipreader
53 uint32_t mNameLen; // length of dirname
54 nsCString mBuffer; // storage for generated text of stream
55 uint32_t mCurPos; // Current position in buffer
56 uint32_t mArrPos; // current position within mArray
57 nsTArray<nsCString> mArray; // array of names in (zip) directory
59 typedef enum {
60 MODE_NOTINITED,
61 MODE_CLOSED,
62 MODE_DIRECTORY,
63 MODE_INFLATE,
64 MODE_COPY
65 } JISMode;
67 JISMode mMode; // Modus of the stream
69 nsresult ContinueInflate(char* aBuf, uint32_t aCount, uint32_t* aBytesRead);
70 nsresult ReadDirectory(char* aBuf, uint32_t aCount, uint32_t* aBytesRead);
71 uint32_t CopyDataToBuffer(char*& aBuffer, uint32_t& aCount);
74 #endif /* nsJARINPUTSTREAM_h__ */