Bug 1918529 - fix some subpixel misalignment issues with gfx.webrender.svg-filter...
[gecko.git] / modules / libjar / nsJARInputStream.h
blob8b6eddf2994019796bf5d81e7935cb09116fd290
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 char* aDir);
41 private:
42 ~nsJARInputStream() { Close(); }
44 RefPtr<nsZipHandle> mFd; // handle for reading
45 uint32_t mOutSize; // inflated size
46 uint32_t mInCrc; // CRC as provided by the zipentry
47 uint32_t mOutCrc; // CRC as calculated by me
48 z_stream mZs; // zip data structure
50 /* For directory reading */
51 RefPtr<nsJAR> mJar; // string reference to zipreader
52 uint32_t mNameLen; // length of dirname
53 nsCString mBuffer; // storage for generated text of stream
54 uint32_t mCurPos; // Current position in buffer
55 uint32_t mArrPos; // current position within mArray
56 nsTArray<nsCString> mArray; // array of names in (zip) directory
58 typedef enum {
59 MODE_NOTINITED,
60 MODE_CLOSED,
61 MODE_DIRECTORY,
62 MODE_INFLATE,
63 MODE_COPY
64 } JISMode;
66 JISMode mMode; // Modus of the stream
68 nsresult ContinueInflate(char* aBuf, uint32_t aCount, uint32_t* aBytesRead);
69 nsresult ReadDirectory(char* aBuf, uint32_t aCount, uint32_t* aBytesRead);
70 uint32_t CopyDataToBuffer(char*& aBuffer, uint32_t& aCount);
73 #endif /* nsJARINPUTSTREAM_h__ */