Bug 594172 - ZipWriter write()s too often r=Mossop a=2.0

This commit is contained in:
Taras Glek 2010-09-14 15:47:47 -04:00
parent 12f7c089a6
commit cf38d1c59a
3 changed files with 23 additions and 14 deletions

View File

@ -152,8 +152,7 @@ NS_IMETHODIMP nsZipDataStream::OnStopRequest(nsIRequest *aRequest,
inline nsresult nsZipDataStream::CompleteEntry()
{
nsresult rv = mStream->Flush();
NS_ENSURE_SUCCESS(rv, rv);
nsresult rv;
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(mStream, &rv);
NS_ENSURE_SUCCESS(rv, rv);
PRInt64 pos;
@ -161,17 +160,7 @@ inline nsresult nsZipDataStream::CompleteEntry()
NS_ENSURE_SUCCESS(rv, rv);
mHeader->mCSize = pos - mHeader->mOffset - mHeader->GetFileHeaderLength();
// Go back and rewrite the file header
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, mHeader->mOffset);
NS_ENSURE_SUCCESS(rv, rv);
rv = mHeader->WriteFileHeader(mStream);
NS_ENSURE_SUCCESS(rv, rv);
rv = mStream->Flush();
NS_ENSURE_SUCCESS(rv, rv);
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, pos);
NS_ENSURE_SUCCESS(rv, rv);
mHeader->mWriteOnClose = PR_TRUE;
return NS_OK;
}

View File

@ -78,6 +78,7 @@ public:
mDisk(0),
mIAttr(0),
mInited(PR_FALSE),
mWriteOnClose(PR_FALSE),
mExtraField(NULL),
mLocalExtraField(NULL)
{
@ -105,6 +106,7 @@ public:
PRUint16 mDisk;
PRUint16 mIAttr;
PRPackedBool mInited;
PRPackedBool mWriteOnClose;
nsCString mName;
nsCString mComment;
nsAutoArrayPtr<PRUint8> mExtraField;

View File

@ -301,7 +301,7 @@ NS_IMETHODIMP nsZipWriter::Open(nsIFile *aFile, PRInt32 aIoFlags)
return rv;
}
rv = NS_NewBufferedOutputStream(getter_AddRefs(mStream), stream, 0x800);
rv = NS_NewBufferedOutputStream(getter_AddRefs(mStream), stream, 3 * 1024 * 1024);
if (NS_FAILED(rv)) {
stream->Close();
mHeaders.Clear();
@ -711,6 +711,24 @@ NS_IMETHODIMP nsZipWriter::Close()
Cleanup();
return rv;
}
// Go back and rewrite the file headers
for (PRInt32 i = 0; i < mHeaders.Count(); i++) {
nsZipHeader *header = mHeaders[i];
if (!header->mWriteOnClose)
continue;
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, header->mOffset);
if (NS_FAILED(rv)) {
Cleanup();
return rv;
}
rv = header->WriteFileHeader(mStream);
if (NS_FAILED(rv)) {
Cleanup();
return rv;
}
}
}
nsresult rv = mStream->Close();