Bug 695843 part 4 - Allow nsZipCursor to always use the given buffer. r=tglek

This commit is contained in:
Mike Hommey 2011-12-08 11:03:36 +01:00
parent 911ad54a40
commit b28c6a9643
2 changed files with 28 additions and 6 deletions

View File

@ -1038,7 +1038,7 @@ nsZipCursor::~nsZipCursor()
}
}
PRUint8* nsZipCursor::Read(PRUint32 *aBytesRead) {
PRUint8* nsZipCursor::ReadOrCopy(PRUint32 *aBytesRead, bool aCopy) {
int zerr;
PRUint8 *buf = nsnull;
bool verifyCRC = true;
@ -1048,10 +1048,17 @@ PRUint8* nsZipCursor::Read(PRUint32 *aBytesRead) {
MOZ_WIN_MEM_TRY_BEGIN
switch (mItem->Compression()) {
case STORED:
*aBytesRead = mZs.avail_in;
buf = mZs.next_in;
mZs.next_in += mZs.avail_in;
mZs.avail_in = 0;
if (!aCopy) {
*aBytesRead = mZs.avail_in;
buf = mZs.next_in;
mZs.next_in += mZs.avail_in;
mZs.avail_in = 0;
} else {
*aBytesRead = mZs.avail_in > mBufSize ? mBufSize : mZs.avail_in;
memcpy(mBuf, mZs.next_in, *aBytesRead);
mZs.avail_in -= *aBytesRead;
mZs.next_in += *aBytesRead;
}
break;
case DEFLATED:
buf = mBuf;

View File

@ -310,9 +310,24 @@ public:
* @param aBytesRead Outparam for number of bytes read.
* @return data read or NULL if item is corrupted.
*/
PRUint8* Read(PRUint32 *aBytesRead);
PRUint8* Read(PRUint32 *aBytesRead) {
return ReadOrCopy(aBytesRead, false);
}
/**
* Performs a copy. It always uses aBuf(passed in constructor).
*
* @param aBytesRead Outparam for number of bytes read.
* @return data read or NULL if item is corrupted.
*/
PRUint8* Copy(PRUint32 *aBytesRead) {
return ReadOrCopy(aBytesRead, true);
}
private:
/* Actual implementation for both Read and Copy above */
PRUint8* ReadOrCopy(PRUint32 *aBytesRead, bool aCopy);
nsZipItem *mItem;
PRUint8 *mBuf;
PRUint32 mBufSize;