modules/libjar/nsJARInputStream.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:97f9ee1b1eac
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 #include "mozilla/Attributes.h"
14
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 }
29
30 ~nsJARInputStream() { Close(); }
31
32 NS_DECL_THREADSAFE_ISUPPORTS
33 NS_DECL_NSIINPUTSTREAM
34
35 // takes ownership of |fd|, even on failure
36 nsresult InitFile(nsJAR *aJar, nsZipItem *item);
37
38 nsresult InitDirectory(nsJAR *aJar,
39 const nsACString& aJarDirSpec,
40 const char* aDir);
41
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
48
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
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__ */
73

mercurial