[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Ftpapi] Need to understand how decode from Base64 to Ascii



Hi Luca,

I also don't understand why this works, it seems like it should not, and is not the way that I would do it.

-SK


On 6/18/2018 4:42 AM, Luca Giammattei wrote:
Il 15/06/2018 23:29, Scott Klement ha scritto:

Hi Scott, i did some further testing and now everything seems to work fine, even if i dn't understand exactly what is happening under the hood.

This is what i have done:

- first clean up the flags and mode to create/open the file;
- then i split the two operations, create the file, then close it then open the file to write data into it; - decode data from bas64 sring and write it to the ascii file already created.
- close the file.

The file is readble both from iseries and from windows.

My fellow desk partner thinks the problem lies in the ccsid/codepage i used to create the file, in my previous effort i created the file as 819 now as 850.

This is a snippet form my code

D fourbytes       s              4A   Inz
D decbuf          s              3a   Inz
d declen          s             10i 0 Inz
D fd              s             10i 0 Inz
D rc              s             10i 0 Inz
D flags           S             10U 0 Inz
D mode            S             10U 0 Inz
D CodePage        s             10U 0 inz(850)
d pathToFile      s             80a   Inz

 /free

       Flags = O_CREAT + O_WRONLY + O_CODEPAGE;
       Mode =  S_IWUSR + S_IRUSR + S_IRGRP + S_IROTH;

       fd = openf( %Trim(pathToFile) : flags : mode : CodePage );
       Closef(fd);

       clear flags;
       clear mode;
       flags = O_WRONLY + O_TEXTDATA;

       fd = openf( %Trim(pathToFile) : flags);

         DoW %Len(%Trim(File)) > 0;
           FourBytes = %subst(File:1:4);
           If %len(%Trim(File)) > 4;
             File = %subst(File:5);
           Else;
             File = '';
           EndIf;
           declen = base64_decode(%addr(fourbytes):4
                                 :%addr(decbuf):3);
           http_xlatep(declen:%addr(decbuf):TO_EBCDIC);
           writef(fd:%addr(decbuf):declen);
         ENDDO;

         closef(fd);

 /end-free



--
_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi