2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-11-30 18:05:54 +00:00
|
|
|
|
|
|
|
#include "nsBase64Encoder.h"
|
|
|
|
|
2018-02-19 15:28:00 +00:00
|
|
|
#include "mozilla/Base64.h"
|
2007-11-30 18:05:54 +00:00
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsBase64Encoder, nsIOutputStream)
|
2007-11-30 18:05:54 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBase64Encoder::Close()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBase64Encoder::Flush()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsBase64Encoder::Write(const char* aBuf, uint32_t aCount, uint32_t* _retval)
|
2007-11-30 18:05:54 +00:00
|
|
|
{
|
|
|
|
mData.Append(aBuf, aCount);
|
|
|
|
*_retval = aCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsBase64Encoder::WriteFrom(nsIInputStream* aStream, uint32_t aCount,
|
|
|
|
uint32_t* _retval)
|
2007-11-30 18:05:54 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBase64Encoder::WriteSegments(nsReadSegmentFun aReader,
|
|
|
|
void* aClosure,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aCount,
|
|
|
|
uint32_t* _retval)
|
2007-11-30 18:05:54 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsBase64Encoder::IsNonBlocking(bool* aNonBlocking)
|
2007-11-30 18:05:54 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
*aNonBlocking = false;
|
2007-11-30 18:05:54 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-06-20 09:19:52 +00:00
|
|
|
nsBase64Encoder::Finish(nsACString& result)
|
2007-11-30 18:05:54 +00:00
|
|
|
{
|
2018-02-19 15:28:00 +00:00
|
|
|
nsresult rv = mozilla::Base64Encode(mData, result);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2007-11-30 18:05:54 +00:00
|
|
|
|
|
|
|
// Free unneeded memory and allow reusing the object
|
|
|
|
mData.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|