3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is Netscape Communicator source code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1999
21 * the Initial Developer. All Rights Reserved.
24 * Mitch Stoltz <mstoltz@netscape.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef nsJARINPUTSTREAM_h__
41 #define nsJARINPUTSTREAM_h__
43 #include "nsIInputStream.h"
47 /*-------------------------------------------------------------------------
48 * Class nsJARInputStream declaration. This class defines the type of the
49 * object returned by calls to nsJAR::GetInputStream(filename) for the
50 * purpose of reading a file item out of a JAR file.
51 *------------------------------------------------------------------------*/
52 class nsJARInputStream
: public nsIInputStream
56 mOutSize(0), mInCrc(0), mOutCrc(0), mCurPos(0),
59 memset(&mZs
, 0, sizeof(z_stream
));
62 ~nsJARInputStream() { Close(); }
65 NS_DECL_NSIINPUTSTREAM
67 // takes ownership of |fd|, even on failure
68 nsresult
InitFile(nsJAR
*aJar
, nsZipItem
*item
);
70 nsresult
InitDirectory(nsJAR
*aJar
,
71 const nsACString
& aJarDirSpec
,
75 nsRefPtr
<nsZipHandle
> mFd
; // handle for reading
76 PRUint32 mOutSize
; // inflated size
77 PRUint32 mInCrc
; // CRC as provided by the zipentry
78 PRUint32 mOutCrc
; // CRC as calculated by me
79 z_stream mZs
; // zip data structure
81 /* For directory reading */
82 nsRefPtr
<nsJAR
> mJar
; // string reference to zipreader
83 PRUint32 mNameLen
; // length of dirname
84 nsCString mBuffer
; // storage for generated text of stream
85 PRUint32 mCurPos
; // Current position in buffer
86 PRUint32 mArrPos
; // current position within mArray
87 nsTArray
<nsCString
> mArray
; // array of names in (zip) directory
97 JISMode mMode
; // Modus of the stream
99 nsresult
ContinueInflate(char* aBuf
, PRUint32 aCount
, PRUint32
* aBytesRead
);
100 nsresult
ReadDirectory(char* aBuf
, PRUint32 aCount
, PRUint32
* aBytesRead
);
101 PRUint32
CopyDataToBuffer(char* &aBuffer
, PRUint32
&aCount
);
104 #endif /* nsJARINPUTSTREAM_h__ */