Bug 780145 - ArchiveReader doesn't unzip large files, r=jst

This commit is contained in:
Andrea Marchesini 2012-08-08 11:11:15 -07:00
Родитель 437a8060e9
Коммит ca64b201c8
8 изменённых файлов: 58 добавлений и 15 удалений

Просмотреть файл

@ -13,8 +13,14 @@ USING_FILE_NAMESPACE
NS_IMPL_THREADSAFE_ISUPPORTS0(ArchiveItem)
ArchiveItem::ArchiveItem()
{
MOZ_COUNT_CTOR(ArchiveItem);
}
ArchiveItem::~ArchiveItem()
{
MOZ_COUNT_DTOR(ArchiveItem);
}

Просмотреть файл

@ -24,6 +24,7 @@ class ArchiveItem : public nsISupports
public:
NS_DECL_ISUPPORTS
ArchiveItem();
virtual ~ArchiveItem();
// Getter/Setter for the type

Просмотреть файл

@ -23,11 +23,13 @@ ArchiveReader::ArchiveReader()
mWindow(nullptr),
mStatus(NOT_STARTED)
{
MOZ_COUNT_CTOR(ArchiveReader);
nsLayoutStatics::AddRef();
}
ArchiveReader::~ArchiveReader()
{
MOZ_COUNT_DTOR(ArchiveReader);
nsLayoutStatics::Release();
}

Просмотреть файл

@ -51,6 +51,7 @@ ArchiveRequest::ArchiveRequest(nsIDOMWindow* aWindow,
: DOMRequest(aWindow),
mArchiveReader(aReader)
{
MOZ_COUNT_CTOR(ArchiveRequest);
nsLayoutStatics::AddRef();
/* An event to make this request asynchronous: */
@ -60,6 +61,7 @@ ArchiveRequest::ArchiveRequest(nsIDOMWindow* aWindow,
ArchiveRequest::~ArchiveRequest()
{
MOZ_COUNT_DTOR(ArchiveRequest);
nsLayoutStatics::Release();
}

Просмотреть файл

@ -22,6 +22,12 @@ ArchiveZipItem::ArchiveZipItem(const char* aFilename,
: mFilename(aFilename),
mCentralStruct(aCentralStruct)
{
MOZ_COUNT_CTOR(ArchiveZipItem);
}
ArchiveZipItem::~ArchiveZipItem()
{
MOZ_COUNT_DTOR(ArchiveZipItem);
}
// Getter/Setter for the filename

Просмотреть файл

@ -19,6 +19,7 @@ class ArchiveZipItem : public ArchiveItem
public:
ArchiveZipItem(const char* aFilename,
ZipCentral& aCentralStruct);
virtual ~ArchiveZipItem();
void SetFilename(const nsCString& aFilename);
nsCString GetFilename();

Просмотреть файл

@ -30,11 +30,14 @@ public:
mFilename(aFilename),
mStart(aStart),
mLength(aLength),
mRunning(false)
{}
~ArchiveInputStream()
mStatus(NotStarted)
{
MOZ_COUNT_CTOR(ArchiveInputStream);
}
virtual ~ArchiveInputStream()
{
MOZ_COUNT_DTOR(ArchiveInputStream);
Close();
}
@ -53,7 +56,11 @@ private: // data
z_stream mZs;
bool mRunning;
enum {
NotStarted,
Started,
Done
} mStatus;
struct {
nsCOMPtr<nsIInputStream> inputStream;
@ -147,16 +154,15 @@ ArchiveInputStream::Init()
}
}
mRunning = true;
return NS_OK;
}
NS_IMETHODIMP
ArchiveInputStream::Close()
{
if (mRunning) {
if (mStatus != NotStarted) {
inflateEnd(&mZs);
mRunning = false;
mStatus = NotStarted;
}
return NS_OK;
@ -177,18 +183,22 @@ ArchiveInputStream::Read(char* aBuffer,
NS_ENSURE_ARG_POINTER(aBuffer);
NS_ENSURE_ARG_POINTER(_retval);
PRUint32 ret;
nsresult rv;
// This is the first time:
if (!mRunning) {
if (mStatus == NotStarted) {
mStatus = Started;
rv = Init();
if (rv != NS_OK)
return rv;
// Let's set avail_out to -1 so we read something from the stream.
mZs.avail_out = (uInt)-1;
}
// Nothing more can be read
if (mData.sizeToBeRead == 0) {
if (mStatus == Done) {
*_retval = 0;
return NS_OK;
}
@ -200,15 +210,20 @@ ArchiveInputStream::Read(char* aBuffer,
(mData.sizeToBeRead > aCount ?
aCount : mData.sizeToBeRead),
_retval);
if (rv == NS_OK)
if (rv == NS_OK) {
mData.sizeToBeRead -= *_retval;
if (mData.sizeToBeRead == 0)
mStatus = Done;
}
return rv;
}
// We have nothing ready to be processed:
if (mZs.avail_out == 0)
if (mZs.avail_out != 0 && mData.sizeToBeRead != 0)
{
PRUint32 ret;
rv = mData.inputStream->Read((char*)mData.input,
(mData.sizeToBeRead > sizeof(mData.input) ?
sizeof(mData.input) : mData.sizeToBeRead),
@ -230,10 +245,13 @@ ArchiveInputStream::Read(char* aBuffer,
mZs.avail_out = aCount;
mZs.next_out = (unsigned char*)aBuffer;
ret = inflate(&mZs, mData.sizeToBeRead ? Z_NO_FLUSH : Z_FINISH);
if (ret != Z_OK && ret != Z_STREAM_END)
int ret = inflate(&mZs, mData.sizeToBeRead ? Z_NO_FLUSH : Z_FINISH);
if (ret != Z_BUF_ERROR && ret != Z_OK && ret != Z_STREAM_END)
return NS_ERROR_UNEXPECTED;
if (ret == Z_STREAM_END)
mStatus = Done;
*_retval = aCount - mZs.avail_out;
return NS_OK;
}

Просмотреть файл

@ -30,6 +30,7 @@ public:
mFilename(aName)
{
NS_ASSERTION(mArchiveReader, "must have a reader");
MOZ_COUNT_CTOR(ArchiveZipFile);
}
ArchiveZipFile(const nsAString& aName,
@ -44,6 +45,12 @@ public:
mFilename(aName)
{
NS_ASSERTION(mArchiveReader, "must have a reader");
MOZ_COUNT_CTOR(ArchiveZipFile);
}
virtual ~ArchiveZipFile()
{
MOZ_COUNT_DTOR(ArchiveZipFile);
}
// Overrides: