Manual Reference Pages  - encode_base64 (3m_strings)

NAME

encode_base64-(3f) - [M_strings:ENCODE] encode data using base64 encoding as defined in RFC-4648 (LICENSE:MIT)

CONTENTS

Synopsis
Description
Options
Output
Example
See Also

SYNOPSIS

function encode_base64(text,width) result(out)

     character(len=1),intent(in) :: text(*)
     integer,intent(in),optional :: width
     character(len=1),allocatable :: out(:)

DESCRIPTION

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

OPTIONS

TEXT Data to encode
WIDTH wrap encoded lines after specified number of characters (default 76). Use 0 to disable line wrapping

OUTPUT

OUT array of encoded characters representing input text

EXAMPLE

Sample program:

   program demo_encode_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_encode_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

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


Nemo Release 3.1 encode_base64 (3m_strings) January 10, 2025
Generated by manServer 1.08 from fa70ef89-827c-445a-b50c-5e39500f869b using man macros.