1999-10-26 23:43:26 +04:00
|
|
|
/* nsJARInputStream.h
|
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-10-26 23:43:26 +04:00
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
2005-12-15 16:48:48 +03:00
|
|
|
* The Original Code is Netscape Communicator source code.
|
2004-04-19 02:01:16 +04:00
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Mitch Stoltz <mstoltz@netscape.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-10-26 23:43:26 +04:00
|
|
|
|
|
|
|
#ifndef nsJARINPUTSTREAM_h__
|
|
|
|
#define nsJARINPUTSTREAM_h__
|
|
|
|
|
|
|
|
#include "nsIInputStream.h"
|
2000-01-29 03:03:57 +03:00
|
|
|
#include "nsJAR.h"
|
2009-01-22 07:15:34 +03:00
|
|
|
#include "nsTArray.h"
|
1999-10-26 23:43:26 +04:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
2006-03-30 02:10:37 +04:00
|
|
|
* Class nsJARInputStream declaration. This class defines the type of the
|
|
|
|
* object returned by calls to nsJAR::GetInputStream(filename) for the
|
|
|
|
* purpose of reading a file item out of a JAR file.
|
1999-10-26 23:43:26 +04:00
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
class nsJARInputStream : public nsIInputStream
|
|
|
|
{
|
|
|
|
public:
|
2006-05-02 23:33:09 +04:00
|
|
|
nsJARInputStream() :
|
2009-10-04 21:20:45 +04:00
|
|
|
mOutSize(0), mInCrc(0), mOutCrc(0), mCurPos(0),
|
|
|
|
mMode(MODE_NOTINITED)
|
|
|
|
{
|
|
|
|
memset(&mZs, 0, sizeof(z_stream));
|
|
|
|
}
|
2009-08-13 00:50:12 +04:00
|
|
|
|
2009-10-04 21:20:45 +04:00
|
|
|
~nsJARInputStream() { Close(); }
|
2006-10-10 17:24:57 +04:00
|
|
|
|
1999-10-26 23:43:26 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIINPUTSTREAM
|
|
|
|
|
2007-01-26 02:05:22 +03:00
|
|
|
// takes ownership of |fd|, even on failure
|
2009-10-04 21:20:45 +04:00
|
|
|
nsresult InitFile(nsJAR *aJar, nsZipItem *item);
|
2007-01-26 02:05:22 +03:00
|
|
|
|
2009-08-13 00:50:12 +04:00
|
|
|
nsresult InitDirectory(nsJAR *aJar,
|
2006-10-10 17:24:57 +04:00
|
|
|
const nsACString& aJarDirSpec,
|
|
|
|
const char* aDir);
|
1999-10-26 23:43:26 +04:00
|
|
|
|
2006-05-02 23:33:09 +04:00
|
|
|
private:
|
2009-10-04 21:20:45 +04:00
|
|
|
nsRefPtr<nsZipHandle> mFd; // handle for reading
|
|
|
|
PRUint32 mOutSize; // inflated size
|
|
|
|
PRUint32 mInCrc; // CRC as provided by the zipentry
|
|
|
|
PRUint32 mOutCrc; // CRC as calculated by me
|
|
|
|
z_stream mZs; // zip data structure
|
2009-09-01 23:47:00 +04:00
|
|
|
|
2009-09-03 16:15:19 +04:00
|
|
|
/* For directory reading */
|
2009-10-04 21:20:45 +04:00
|
|
|
nsRefPtr<nsJAR> mJar; // string reference to zipreader
|
|
|
|
PRUint32 mNameLen; // length of dirname
|
|
|
|
nsCString mBuffer; // storage for generated text of stream
|
|
|
|
PRUint32 mCurPos; // Current position in buffer
|
|
|
|
PRUint32 mArrPos; // current position within mArray
|
|
|
|
nsTArray<nsCString> mArray; // array of names in (zip) directory
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
MODE_NOTINITED,
|
|
|
|
MODE_CLOSED,
|
|
|
|
MODE_DIRECTORY,
|
|
|
|
MODE_INFLATE,
|
|
|
|
MODE_COPY
|
|
|
|
} JISMode;
|
|
|
|
|
|
|
|
JISMode mMode; // Modus of the stream
|
2006-10-10 17:24:57 +04:00
|
|
|
|
2006-05-02 23:33:09 +04:00
|
|
|
nsresult ContinueInflate(char* aBuf, PRUint32 aCount, PRUint32* aBytesRead);
|
2006-10-10 17:24:57 +04:00
|
|
|
nsresult ReadDirectory(char* aBuf, PRUint32 aCount, PRUint32* aBytesRead);
|
|
|
|
PRUint32 CopyDataToBuffer(char* &aBuffer, PRUint32 &aCount);
|
1999-10-26 23:43:26 +04:00
|
|
|
};
|
|
|
|
|
2006-03-30 02:10:37 +04:00
|
|
|
#endif /* nsJARINPUTSTREAM_h__ */
|
2006-05-02 23:33:09 +04:00
|
|
|
|