/** * Escribe sobre el output_stream el contenido del * input_stream codificado en base 64 */ int encode(FILE* input_stream, FILE* output_stream) { char input_buffer[3]; char output_buffer[4]; set_endianess(); int bytes_read = fread(input_buffer, sizeof(char), 3, input_stream); while (bytes_read > 0) { if (bytes_read < 3) input_buffer[2] = 0; if (bytes_read < 2) input_buffer[1] = 0; if (!encode_to_base64(input_buffer, output_buffer)) return ENCODE_ERROR; add_padding(bytes_read, output_buffer); int bytes_wrote = fwrite(output_buffer, sizeof(char), 4, output_stream); if (bytes_wrote != 4) return WRITE_ERROR; bytes_read = fread(input_buffer, sizeof(char), 3, input_stream); } return 0; }
static void dump_output(const sk_sp<SkData>& data, const char* name, bool last = true) { if (data) { printf("\t\"%s\": \"", name); encode_to_base64(data->data(), data->size(), stdout); fputs(last ? "\"\n" : "\",\n", stdout); } }