MCPcopy Create free account
hub / github.com/FreeFem/FreeFem-sources / encodeB64

Function encodeB64

plugin/seq/iovtk.cpp:122–156  ·  view source on GitHub ↗

=========================== ===========================

Source from the content-addressed store, hash-verified

120//
121// ===========================
122int encodeB64(int n, unsigned char *inBytes, unsigned char *outBytes) {
123 if (inBytes == NULL || outBytes == NULL || n <= 0) {
124 return 0;
125 }
126
127 int m = n - (n % 3);
128 int ii, jj;
129 jj = 0;
130
131 for (ii = 0; ii < m; ii += 3) {
132 encodeB64_3Bytes(inBytes + ii, outBytes + jj);
133 jj = jj + 4;
134 }
135
136 if (m != n) {
137 unsigned char lastBytes[3] = {0, 0, 0};
138 // give last (n-m) chars
139 lastBytes[0] = inBytes[ii];
140 if ((n - m) == 2) {
141 lastBytes[1] = inBytes[ii + 1];
142 }
143
144 // encoding chars
145 encodeB64_3Bytes(lastBytes, outBytes + jj);
146 // definition of bytes which is not encoding
147 outBytes[jj + 3] = '=';
148 if ((n - m) == 1) {
149 outBytes[jj + 2] = '=';
150 }
151
152 jj = jj + 4;
153 }
154
155 return jj;
156}
157
158int runEncodeB64(int n, unsigned char *inBytes, unsigned char *outBytes) {
159 static int nbcached = 0;

Callers 1

runEncodeB64Function · 0.85

Calls 1

encodeB64_3BytesFunction · 0.85

Tested by

no test coverage detected