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"
|
|
|
|
|
|
|
|
#include "plbase64.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
|
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
|
|
|
|
nsBase64Encoder::Finish(nsCSubstring& result)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
char* b64 = PL_Base64Encode(mData.get(), mData.Length(), nullptr);
|
2007-11-30 18:05:54 +00:00
|
|
|
if (!b64)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
result.Assign(b64);
|
|
|
|
PR_Free(b64);
|
|
|
|
// Free unneeded memory and allow reusing the object
|
|
|
|
mData.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|