Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / modules / libjar / nsJARInputStream.h
blob52ef374aad072a5b4d906d55f20baed2723c6fee
1 /* nsJARInputStream.h
2 *
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
14 * License.
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.
23 * Contributor(s):
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"
44 #include "nsJAR.h"
46 /*-------------------------------------------------------------------------
47 * Class nsJARInputStream declaration. This class defines the type of the
48 * object returned by calls to nsJAR::GetInputStream(filename) for the
49 * purpose of reading a file item out of a JAR file.
50 *------------------------------------------------------------------------*/
51 class nsJARInputStream : public nsIInputStream
53 public:
54 nsJARInputStream() :
55 mFd(nsnull), mInSize(0), mCurPos(0),
56 mInflate(nsnull), mDirectory(0), mClosed(PR_FALSE) { }
58 ~nsJARInputStream() { Close(); }
60 NS_DECL_ISUPPORTS
61 NS_DECL_NSIINPUTSTREAM
63 // takes ownership of |fd|, even on failure
64 nsresult InitFile(nsZipArchive* aZip, nsZipItem *item, PRFileDesc *fd);
66 nsresult InitDirectory(nsZipArchive* aZip,
67 const nsACString& aJarDirSpec,
68 const char* aDir);
70 private:
71 PRFileDesc* mFd; // My own file handle, for reading
72 PRUint32 mInSize; // Size in original file
73 PRUint32 mCurPos; // Current position in input
75 struct InflateStruct {
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
80 unsigned char mReadBuf[ZIP_BUFLEN]; // Readbuffer to inflate from
82 struct InflateStruct * mInflate;
84 /* For directory reading */
85 nsZipArchive* mZip; // the zipReader
86 PRUint32 mNameLen; // length of dirname
87 nsCAutoString mBuffer; // storage for generated text of stream
88 PRUint32 mArrPos; // current position within mArray
89 nsCStringArray mArray; // array of names in (zip) directory
91 PRPackedBool mDirectory;
92 PRPackedBool mClosed; // Whether the stream is closed
94 nsresult ContinueInflate(char* aBuf, PRUint32 aCount, PRUint32* aBytesRead);
95 nsresult ReadDirectory(char* aBuf, PRUint32 aCount, PRUint32* aBytesRead);
96 PRUint32 CopyDataToBuffer(char* &aBuffer, PRUint32 &aCount);
99 #endif /* nsJARINPUTSTREAM_h__ */