1 : /* nsJARInputStream.h
2 : *
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
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/
10 : *
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.
15 : *
16 : * The Original Code is Netscape Communicator source code.
17 : *
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.
22 : *
23 : * Contributor(s):
24 : * Mitch Stoltz <mstoltz@netscape.com>
25 : *
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.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef nsJARINPUTSTREAM_h__
41 : #define nsJARINPUTSTREAM_h__
42 :
43 : #include "nsIInputStream.h"
44 : #include "nsJAR.h"
45 : #include "nsTArray.h"
46 :
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
53 : {
54 : public:
55 1289 : nsJARInputStream() :
56 : mOutSize(0), mInCrc(0), mOutCrc(0), mCurPos(0),
57 1289 : mMode(MODE_NOTINITED)
58 : {
59 1289 : memset(&mZs, 0, sizeof(z_stream));
60 1289 : }
61 :
62 1289 : ~nsJARInputStream() { Close(); }
63 :
64 : NS_DECL_ISUPPORTS
65 : NS_DECL_NSIINPUTSTREAM
66 :
67 : // takes ownership of |fd|, even on failure
68 : nsresult InitFile(nsJAR *aJar, nsZipItem *item);
69 :
70 : nsresult InitDirectory(nsJAR *aJar,
71 : const nsACString& aJarDirSpec,
72 : const char* aDir);
73 :
74 : private:
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
80 :
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
88 :
89 : typedef enum {
90 : MODE_NOTINITED,
91 : MODE_CLOSED,
92 : MODE_DIRECTORY,
93 : MODE_INFLATE,
94 : MODE_COPY
95 : } JISMode;
96 :
97 : JISMode mMode; // Modus of the stream
98 :
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);
102 : };
103 :
104 : #endif /* nsJARINPUTSTREAM_h__ */
105 :
|