decode_base64-(3f) - [M_strings:ENCODE] decode data from base64 encoding as defined in RFC-4648 (LICENSE:MIT)
Synopsis
Description
Options
Output
Example
See Also
function decode_base64(text,ignore_garbage) result(out)
character(len=1),intent(in) :: text(*) logical,intent(in),optional :: ignore_garbage character(len=1),allocatable :: out(:)
The data is deencoded as described for the base64-alphabet-encoding in RFC 4648.
TEXT Data to decode IGNORE_GARBAGE when decoding, ignore all characters not in the formal base64 alphabet. This option will attempt to recover from any other non-alphabet bytes in the encoded data.
OUT array of decoded characters
Sample program:
program demo_decode_base64 use,intrinsic :: iso_fortran_env, only : int8, int16, int32, int64 use M_strings, only : switch, encode_base64, decode_base64 implicit none integer :: i character(len=1),parameter :: nl=new_line(’a’) character(len=1),allocatable :: textin(:), textout(:) character(len=*),parameter :: data(*)=[ & ’This is some sample data ’, & ’To encode. Should make it long ’, & ’enough to generate multiple lines ’, & ’of output so can check line wrap ’, & ’functionality as well. ’ & ] ! make a file-like byte stream by trimming lines and adding newlines textin=[(switch(trim(data(i))),new_line(’a’),i=1,size(data))] write(*,’(*(a))’)’input:’,nl,textin ! textout=encode_base64(textin,width=50) write(*,’(*(a))’)’result:’,nl, textout ! write(*,’(*(a))’)’decode result:’,nl, decode_base64(textout) ! end program demo_decode_base64Results:
> input: > This is some sample data > To encode. Should make it long > enough to generate multiple lines > of output so can check line wrap > functionality as well. > > result: > VGhpcyBpcyBzb21lIHNhbXBsZSBkYXRhClRvIGVuY29kZS4gU2 > hvdWxkIG1ha2UgaXQgbG9uZwplbm91Z2ggdG8gZ2VuZXJhdGUg > bXVsdGlwbGUgbGluZXMKb2Ygb3V0cHV0IHNvIGNhbiBjaGVjay > BsaW5lIHdyYXAKZnVuY3Rpb25hbGl0eSBhcyB3ZWxsLgo= > > decode result: > This is some sample data > To encode. Should make it long > enough to generate multiple lines > of output so can check line wrap > functionality as well. >
encode_base64(3), base64(1), uuencode(1), uudecode(1)