1999-10-26 23:43:26 +04:00
|
|
|
/* nsJARInputStream.h
|
|
|
|
*
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
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"
|
2012-06-13 07:27:07 +04:00
|
|
|
#include "mozilla/Attributes.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
|
|
|
*------------------------------------------------------------------------*/
|
2012-06-13 07:27:07 +04:00
|
|
|
class nsJARInputStream MOZ_FINAL : public nsIInputStream
|
1999-10-26 23:43:26 +04:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2013-07-19 06:23:44 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
1999-10-26 23:43:26 +04:00
|
|
|
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:
|
2014-06-25 06:09:14 +04:00
|
|
|
~nsJARInputStream() { Close(); }
|
|
|
|
|
2009-10-04 21:20:45 +04:00
|
|
|
nsRefPtr<nsZipHandle> mFd; // handle for reading
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mOutSize; // inflated size
|
|
|
|
uint32_t mInCrc; // CRC as provided by the zipentry
|
|
|
|
uint32_t mOutCrc; // CRC as calculated by me
|
2009-10-04 21:20:45 +04:00
|
|
|
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
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mNameLen; // length of dirname
|
2009-10-04 21:20:45 +04:00
|
|
|
nsCString mBuffer; // storage for generated text of stream
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mCurPos; // Current position in buffer
|
|
|
|
uint32_t mArrPos; // current position within mArray
|
2009-10-04 21:20:45 +04:00
|
|
|
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
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult ContinueInflate(char* aBuf, uint32_t aCount, uint32_t* aBytesRead);
|
|
|
|
nsresult ReadDirectory(char* aBuf, uint32_t aCount, uint32_t* aBytesRead);
|
|
|
|
uint32_t CopyDataToBuffer(char* &aBuffer, uint32_t &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
|
|
|
|