2007-03-22 10:30:00 -07:00
|
|
|
/* nsJARInputStream.h
|
|
|
|
*
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsJARINPUTSTREAM_h__
|
|
|
|
#define nsJARINPUTSTREAM_h__
|
|
|
|
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsJAR.h"
|
2009-01-21 20:15:34 -08:00
|
|
|
#include "nsTArray.h"
|
2012-06-12 20:27:07 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07: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.
|
|
|
|
*------------------------------------------------------------------------*/
|
2015-03-21 09:28:04 -07:00
|
|
|
class nsJARInputStream final : public nsIInputStream
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsJARInputStream() :
|
2009-10-04 10:20:45 -07:00
|
|
|
mOutSize(0), mInCrc(0), mOutCrc(0), mCurPos(0),
|
|
|
|
mMode(MODE_NOTINITED)
|
|
|
|
{
|
|
|
|
memset(&mZs, 0, sizeof(z_stream));
|
|
|
|
}
|
2009-08-12 13:50:12 -07:00
|
|
|
|
2013-07-18 19:23:44 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_NSIINPUTSTREAM
|
|
|
|
|
|
|
|
// takes ownership of |fd|, even on failure
|
2009-10-04 10:20:45 -07:00
|
|
|
nsresult InitFile(nsJAR *aJar, nsZipItem *item);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-12 13:50:12 -07:00
|
|
|
nsresult InitDirectory(nsJAR *aJar,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsACString& aJarDirSpec,
|
|
|
|
const char* aDir);
|
|
|
|
|
|
|
|
private:
|
2014-06-24 19:09:14 -07:00
|
|
|
~nsJARInputStream() { Close(); }
|
|
|
|
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<nsZipHandle> mFd; // handle for reading
|
2012-08-22 08:56:38 -07: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 10:20:45 -07:00
|
|
|
z_stream mZs; // zip data structure
|
2009-09-01 12:47:00 -07:00
|
|
|
|
2009-09-03 05:15:19 -07:00
|
|
|
/* For directory reading */
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<nsJAR> mJar; // string reference to zipreader
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mNameLen; // length of dirname
|
2009-10-04 10:20:45 -07:00
|
|
|
nsCString mBuffer; // storage for generated text of stream
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mCurPos; // Current position in buffer
|
|
|
|
uint32_t mArrPos; // current position within mArray
|
2009-10-04 10:20:45 -07: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
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsJARINPUTSTREAM_h__ */
|
|
|
|
|