MCPcopy Create free account
hub / github.com/Tencent/UnLua / b64encode

Function b64encode

Plugins/UnLuaExtensions/LuaSocket/Source/src/mime.cpp:262–280  ·  view source on GitHub ↗

-------------------------------------------------------------------------*\ * Acumulates bytes in input buffer until 3 bytes are available. * Translate the 3 bytes into Base64 form and append to buffer. * Returns new number of bytes in buffer. \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

260* Returns new number of bytes in buffer.
261\*-------------------------------------------------------------------------*/
262static size_t b64encode(UC c, UC *input, size_t size,
263 luaL_Buffer *buffer)
264{
265 input[size++] = c;
266 if (size == 3) {
267 UC code[4];
268 unsigned long value = 0;
269 value += input[0]; value <<= 8;
270 value += input[1]; value <<= 8;
271 value += input[2];
272 code[3] = b64base[value & 0x3f]; value >>= 6;
273 code[2] = b64base[value & 0x3f]; value >>= 6;
274 code[1] = b64base[value & 0x3f]; value >>= 6;
275 code[0] = b64base[value];
276 luaL_addlstring(buffer, (char *) code, 4);
277 size = 0;
278 }
279 return size;
280}
281
282/*-------------------------------------------------------------------------*\
283* Encodes the Base64 last 1 or 2 bytes and adds padding '='

Callers 1

mime_global_b64Function · 0.85

Calls 1

luaL_addlstringFunction · 0.85

Tested by

no test coverage detected