encodeIntoByteArray

fun Base64.encodeIntoByteArray(source: ByteString, destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = source.size): Int(source)

Encodes bytes from the specified source byte string or its subrange and writes resulting symbols into the destination array. Returns the number of symbols written.

If the size of the source byte string or its subrange is not an integral multiple of 3, the result is padded with '=' to an integral multiple of 4 symbols.

Return

the number of symbols written into destination array.

Parameters

source

the byte string to encode bytes from.

destination

the array to write symbols into.

destinationOffset

the starting index in the destination array to write symbols to, 0 by default.

startIndex

the beginning (inclusive) of the subrange to encode, 0 by default.

endIndex

the end (exclusive) of the subrange to encode, size of the source byte string by default.

Throws

when the resulting symbols don't fit into the destination array starting at the specified destinationOffset, or when that index is out of the destination array indices range.

when startIndex > endIndex.