diff --git a/content/base/src/nsDOMFileReader.cpp b/content/base/src/nsDOMFileReader.cpp index f8363429b32..825ac1d20b2 100644 --- a/content/base/src/nsDOMFileReader.cpp +++ b/content/base/src/nsDOMFileReader.cpp @@ -360,28 +360,6 @@ nsDOMFileReader::OnStartRequest(nsIRequest *request, nsISupports *ctxt) return NS_OK; } -static -NS_METHOD -ReadFuncBinaryString(nsIInputStream* in, - void* closure, - const char* fromRawSegment, - PRUint32 toOffset, - PRUint32 count, - PRUint32 *writeCount) -{ - PRUnichar* dest = static_cast(closure) + toOffset; - PRUnichar* end = dest + count; - const unsigned char* source = (const unsigned char*)fromRawSegment; - while (dest != end) { - *dest = *source; - ++dest; - ++source; - } - *writeCount = count; - - return NS_OK; -} - NS_IMETHODIMP nsDOMFileReader::OnDataAvailable(nsIRequest *aRequest, nsISupports *aContext, @@ -389,21 +367,6 @@ nsDOMFileReader::OnDataAvailable(nsIRequest *aRequest, PRUint32 aOffset, PRUint32 aCount) { - //Continuously update our binary string as data comes in - if (mDataFormat == FILE_AS_BINARY) { - PRUint32 oldLen = mResult.Length(); - PRUnichar *buf = nsnull; - mResult.GetMutableData(&buf, oldLen + aCount); - NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY); - - PRUint32 bytesRead; - aInputStream->ReadSegments(ReadFuncBinaryString, buf + oldLen, aCount, - &bytesRead); - NS_ASSERTION(bytesRead == aCount, "failed to read data"); - - return NS_OK; - } - //Update memory buffer to reflect the contents of the file mFileData = (char *)PR_Realloc(mFileData, aOffset + aCount); NS_ENSURE_TRUE(mFileData, NS_ERROR_OUT_OF_MEMORY); @@ -412,6 +375,27 @@ nsDOMFileReader::OnDataAvailable(nsIRequest *aRequest, mDataLen += aCount; mReadTransferred = mDataLen; + //Continuously update our binary string as data comes in + if (mDataFormat == FILE_AS_BINARY) { + PRUint32 oldLen = mResult.Length(); + PRUint32 newLen = oldLen + aCount; + PRUnichar *buf; + + if (mResult.GetMutableData(&buf, newLen) != newLen) { + return NS_ERROR_OUT_OF_MEMORY; + } + + PRUnichar *bufEnd = buf + newLen; + buf += oldLen; + + char *source = mFileData + aOffset; + while (buf < bufEnd) { + *buf = *source; + ++buf; + ++source; + } + } + //Notify the timer is the appropriate timeframe has passed if (mTimerIsActive) { mProgressEventWasDelayed = PR_TRUE; @@ -485,7 +469,6 @@ nsDOMFileReader::ReadFileContent(nsIDOMFile* aFile, mDataFormat = aDataFormat; mCharset = aCharset; mError = nsnull; - SetDOMStringToNull(mResult); //Obtain the nsDOMFile's underlying nsIFile nsresult rv; diff --git a/content/base/test/test_fileapi.html b/content/base/test/test_fileapi.html index d545bb5df37..e37a3690a01 100644 --- a/content/base/test/test_fileapi.html +++ b/content/base/test/test_fileapi.html @@ -20,235 +20,272 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=414796