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"
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
{
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
);
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
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__ */