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 nsACString
& aJarDirSpec
,
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
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__ */