Manual Reference Pages  - decode_base64 (3m_strings)

NAME

decode_base64-(3f) - [M_strings:ENCODE] decode data from base64 encoding as defined in RFC-4648 (LICENSE:MIT)

CONTENTS

Synopsis
Description
Options
Output
Example
See Also

SYNOPSIS

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(:)

DESCRIPTION

The data is deencoded as described for the base64-alphabet-encoding in RFC 4648.

OPTIONS

TEXT
  The 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.

OUTPUT

OUT array of decoded characters

EXAMPLE

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_base64

Results:

    > 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.
    >

SEE ALSO

encode_base64(3), base64(1), uuencode(1), uudecode(1)


Nemo Release 3.1 decode_base64 (3m_strings) January 10, 2025
Generated by manServer 1.08 from 8699ca81-15dd-4858-89b1-9e0c75be6808 using man macros.