Project

General

Profile

Up

base64encodeP

Encode a read-file reference in base64.

This function is based from the PHP source code and it seems slightly faster than base64_encode (see below).

This functions contains a part of code under PHP license :
http://www.php.net/license/3_01.txt
You must agree the terms of this (free) license and inform the users.

Prototype :

fun [P] S

  • P : a read-file reference

Return : S the encoded content of the file.

See also

Example :

Send an image file to a web server

fun CBreceive (inet, u, data, err)=
  if err == 0 then
  (
    _fooS strcat ">>>>>>>CBreceive current>>>>>>> " data;
    let u -> [s] in
    mutate u <- [strcat s data];
    0
  )
  else if err == 1 then
  (
    let u -> [s] in
    _fooS strcat ">>>>>>>CBreceive end>>>>>>> " s;
    _closemachine
  )
  else
  (
    _fooS strcat ">>>>>>>CBreceive err>>>>>>> " itoa err;
    0
  );;

fun main ()=
  _showconsole;
  let _getpack _checkpack "examples/image.jpg" -> file in  // get the file content
  let base64encodeP file -> file64 in  // encode to base64
  let strtoweb file64 -> file64web in  // convert to web character
  let "http://domin.tld/post.php" -> url in
  let strcat "image=" file64web -> data in
  INETGetURLex2 _channel "POST" url "content-type: application/x-www-form-urlencoded" data 0 @CBreceive [""];
  0;;