Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "nsBase64Encoder.h" |
michael@0 | 6 | |
michael@0 | 7 | #include "plbase64.h" |
michael@0 | 8 | #include "prmem.h" |
michael@0 | 9 | |
michael@0 | 10 | NS_IMPL_ISUPPORTS(nsBase64Encoder, nsIOutputStream) |
michael@0 | 11 | |
michael@0 | 12 | NS_IMETHODIMP |
michael@0 | 13 | nsBase64Encoder::Close() |
michael@0 | 14 | { |
michael@0 | 15 | return NS_OK; |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | NS_IMETHODIMP |
michael@0 | 19 | nsBase64Encoder::Flush() |
michael@0 | 20 | { |
michael@0 | 21 | return NS_OK; |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | NS_IMETHODIMP |
michael@0 | 25 | nsBase64Encoder::Write(const char* aBuf, uint32_t aCount, uint32_t* _retval) |
michael@0 | 26 | { |
michael@0 | 27 | mData.Append(aBuf, aCount); |
michael@0 | 28 | *_retval = aCount; |
michael@0 | 29 | return NS_OK; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | NS_IMETHODIMP |
michael@0 | 33 | nsBase64Encoder::WriteFrom(nsIInputStream* aStream, uint32_t aCount, |
michael@0 | 34 | uint32_t* _retval) |
michael@0 | 35 | { |
michael@0 | 36 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | NS_IMETHODIMP |
michael@0 | 40 | nsBase64Encoder::WriteSegments(nsReadSegmentFun aReader, |
michael@0 | 41 | void* aClosure, |
michael@0 | 42 | uint32_t aCount, |
michael@0 | 43 | uint32_t* _retval) |
michael@0 | 44 | { |
michael@0 | 45 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | NS_IMETHODIMP |
michael@0 | 49 | nsBase64Encoder::IsNonBlocking(bool* aNonBlocking) |
michael@0 | 50 | { |
michael@0 | 51 | *aNonBlocking = false; |
michael@0 | 52 | return NS_OK; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | nsresult |
michael@0 | 56 | nsBase64Encoder::Finish(nsCSubstring& result) |
michael@0 | 57 | { |
michael@0 | 58 | char* b64 = PL_Base64Encode(mData.get(), mData.Length(), nullptr); |
michael@0 | 59 | if (!b64) |
michael@0 | 60 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 61 | |
michael@0 | 62 | result.Assign(b64); |
michael@0 | 63 | PR_Free(b64); |
michael@0 | 64 | // Free unneeded memory and allow reusing the object |
michael@0 | 65 | mData.Truncate(); |
michael@0 | 66 | return NS_OK; |
michael@0 | 67 | } |