mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-15 00:02:49 +03:00
Base64: add option to disable any newlines in output. (#3208)
Closes #3194
This commit is contained in:
committed by
Ivan Grokhotkov
parent
ca3a1728d0
commit
157698bef9
15
cores/esp8266/base64.cpp
Normal file → Executable file
15
cores/esp8266/base64.cpp
Normal file → Executable file
@ -35,13 +35,20 @@ extern "C" {
|
||||
* @param length size_t
|
||||
* @return String
|
||||
*/
|
||||
String base64::encode(uint8_t * data, size_t length) {
|
||||
String base64::encode(uint8_t * data, size_t length, bool doNewLines) {
|
||||
// base64 needs more size then the source data
|
||||
size_t size = ((length * 1.6f) + 1);
|
||||
char * buffer = (char *) malloc(size);
|
||||
if(buffer) {
|
||||
base64_encodestate _state;
|
||||
base64_init_encodestate(&_state);
|
||||
if(doNewLines)
|
||||
{
|
||||
base64_init_encodestate(&_state);
|
||||
}
|
||||
else
|
||||
{
|
||||
base64_init_encodestate_nonewlines(&_state);
|
||||
}
|
||||
int len = base64_encode_block((const char *) &data[0], length, &buffer[0], &_state);
|
||||
len = base64_encode_blockend((buffer + len), &_state);
|
||||
|
||||
@ -57,7 +64,7 @@ String base64::encode(uint8_t * data, size_t length) {
|
||||
* @param text String
|
||||
* @return String
|
||||
*/
|
||||
String base64::encode(String text) {
|
||||
return base64::encode((uint8_t *) text.c_str(), text.length());
|
||||
String base64::encode(String text, bool doNewLines) {
|
||||
return base64::encode((uint8_t *) text.c_str(), text.length(), doNewLines);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user