Function

GLibbase64_encode_step

Declaration

gsize
g_base64_encode_step (
  const guchar* in,
  gsize len,
  gboolean break_lines,
  gchar* out,
  gint* state,
  gint* save
)

Description

Incrementally encode a sequence of binary data into its Base-64 stringified representation. By calling this function multiple times you can convert data in chunks to avoid having to have the full encoded data in memory.

When all of the data has been converted you must call g_base64_encode_close() to flush the saved state.

The output buffer must be large enough to fit all the data that will be written to it. Due to the way base64 encodes you will need at least: (len / 3 + 1) * 4 + 4 bytes (+ 4 may be needed in case of non-zero state). If you enable line-breaking you will need at least: ((len / 3 + 1) * 4 + 4) / 76 + 1 bytes of extra space.

break_lines is typically used when putting base64-encoded data in emails. It breaks the lines at 76 columns instead of putting all of the text on the same line. This avoids problems with long lines in the email system. Note however that it breaks the lines with LF characters, not CR LF sequences, so the result cannot be passed directly to SMTP or certain other protocols.

Available since:2.12

Parameters

in

Type: An array of guint8

The binary data to encode.

The length of the array is specified in the len argument.
The data is owned by the caller of the function.
len

Type: gsize

The length of in.

break_lines

Type: gboolean

Whether to break long lines.

out

Type: An array of guint8

Pointer to destination buffer.

The argument will be set by the function.
The called function takes ownership of the data, and is responsible for freeing it.
state

Type: gint*

Saved state between steps, initialize to 0

The argument will be modified by the function.
save

Type: gint*

Saved state between steps, initialize to 0

The argument will be modified by the function.

Return value

Type: gsize

The number of bytes of output that was written.