NS_IMETHODIMP nsDOMMultipartBlob::GetSize(PRUint64* aLength) { nsresult rv; *aLength = 0; if (mLength) { *aLength = mLength; return NS_OK; } CheckedUint64 length = 0; PRUint32 i; PRUint32 len = mBlobs.Length(); for (i = 0; i < len; i++) { nsIDOMBlob* blob = mBlobs.ElementAt(i).get(); PRUint64 l = 0; rv = blob->GetSize(&l); NS_ENSURE_SUCCESS(rv, rv); length += l; } if (!length.valid()) return NS_ERROR_FAILURE; mLength = length.value(); *aLength = mLength; return NS_OK; }
NS_IMETHODIMP nsDOMMultipartFile::GetSize(PRUint64* aLength) { if (mLength == UINT64_MAX) { CheckedUint64 length = 0; PRUint32 i; PRUint32 len = mBlobs.Length(); for (i = 0; i < len; i++) { nsIDOMBlob* blob = mBlobs.ElementAt(i).get(); PRUint64 l = 0; nsresult rv = blob->GetSize(&l); NS_ENSURE_SUCCESS(rv, rv); length += l; } NS_ENSURE_TRUE(length.valid(), NS_ERROR_FAILURE); mLength = length.value(); } *aLength = mLength; return NS_OK; }
// Makes sure that aStart and aStart + aLength is less then or equal to aSize void ClampToSize(PRUint64 aSize, PRUint64& aStart, PRUint64& aLength) { if (aStart > aSize) { aStart = aLength = 0; } CheckedUint64 endOffset = aStart; endOffset += aLength; if (!endOffset.valid() || endOffset.value() > aSize) { aLength = aSize - aStart; } }