I've got a string of data parsed from an XML transmission.
It's an image encoded in base64.
We save that to the IFS and my program reads and decodes it into a new .PNG file on the IFS.
My problem is that it's returning about 100 blank lines of data.
I'm using ScottK's Base64_decode API.
I think i've found a few things that are holding me up.
#1 is my compile data. (image #1)
#2 my InputData field isnt getting the entire string for some reason. (image #2)
Any advice?
See code Below------------------------------------------------------
H DFTACTGRP(*NO) BNDDIR('FEDEXLIB/BASE64')
H BNDDIR('QC2LE')
/copy FEDEXLIB/QRPGLESRC,BASE64_H
/copy qrpglesrc,httpapi_h
/copy ifsio_h
**************
D BASE64DATA s 72A DIM(43) CTDATA PERRCD(1)
DxAll s 10000a varying
Dlong S 10 0 Inz(*Zero)
*---------------------------------
D ReportError PR
**************
D IFS_file2Var PR 65535a varying
D pfile 256a Value
D InputData s 32767a varying
D OutputData s 32767a varying
D DecData s 32764a
D Decoded s 32764a
D DecLen s 10I 0
D Len s 10I 0
D OutputFile s 200a
D Outfile s 10I 0
D rc s 10I 0
D i s 10I 0
D fd s 10I 0
************************************************** *******************
//Declare the Files
//this is the binary file we save to IFS first!
InputData = IFS_file2Var('/fedexlab/new.bin');
len = %len(InputData);
OutputFile = '/fedexlab/fedex.png';
//Prepare the OUT file
fd = open(outputfile
: O_WRONLY+O_CREAT+O_TRUNC+O_CCSID
: S_IRGRP + S_IWGRP + S_IXGRP +
S_IRUSR + S_IWUSR + S_IXUSR
: 819);
callp close(fd);
fd = open(outputfile:O_WRONLY);
// decode InputData
declen = base64_decode(%addr(InputData : *DATA )
: len
: %addr(OutputData)
: %len(OutputData));
//Write it
callp write(fd: %addr(OutputData: *DATA): declen);
callp close(fd);
*Inlr = *On;
******IFS ==> variable pgm----------------------------***************
P IFS_file2Var b export
D IFS_file2Var pi 65535a varying
D pFile 256a value
*************************
D open pr 10i 0 extproc('open')
D filename * value options(*string)
D openflags 10i 0 value
D mode 10u 0 value options(*nopass)
D codepage 10u 0 value options(*nopass)
D creatcnvid 10u 0 value options(*nopass)
**************************
D read pr 10i 0 extproc('read')
D handle 10i 0 value
D buffer * value
D bytes 10u 0 value
***************
D close pr 10i 0 extproc('close')
D handle 10i 0 value
D data s 65535a
D bytesRead s 10i 0
D handle s 10i 0
D rc s 10i 0
D O_RDONLY c 1
D O_TEXTDATA c 16777216
*----------------------------------------------
handle = open(%trim(pFile): O_RDONLY+O_TEXTDATA);
if handle < 0;
// something is wrong
return '';
endif;
bytesRead = read(handle: %addr(data): %size(data));
if bytesRead <= 0;
return '';
endIf;
rc = close(handle);
return %trim(data);
P e
****************** End of data ****************************************
It's an image encoded in base64.
We save that to the IFS and my program reads and decodes it into a new .PNG file on the IFS.
My problem is that it's returning about 100 blank lines of data.
I'm using ScottK's Base64_decode API.
I think i've found a few things that are holding me up.
#1 is my compile data. (image #1)
#2 my InputData field isnt getting the entire string for some reason. (image #2)
Any advice?
See code Below------------------------------------------------------
H DFTACTGRP(*NO) BNDDIR('FEDEXLIB/BASE64')
H BNDDIR('QC2LE')
/copy FEDEXLIB/QRPGLESRC,BASE64_H
/copy qrpglesrc,httpapi_h
/copy ifsio_h
**************
D BASE64DATA s 72A DIM(43) CTDATA PERRCD(1)
DxAll s 10000a varying
Dlong S 10 0 Inz(*Zero)
*---------------------------------
D ReportError PR
**************
D IFS_file2Var PR 65535a varying
D pfile 256a Value
D InputData s 32767a varying
D OutputData s 32767a varying
D DecData s 32764a
D Decoded s 32764a
D DecLen s 10I 0
D Len s 10I 0
D OutputFile s 200a
D Outfile s 10I 0
D rc s 10I 0
D i s 10I 0
D fd s 10I 0
************************************************** *******************
//Declare the Files
//this is the binary file we save to IFS first!
InputData = IFS_file2Var('/fedexlab/new.bin');
len = %len(InputData);
OutputFile = '/fedexlab/fedex.png';
//Prepare the OUT file
fd = open(outputfile
: O_WRONLY+O_CREAT+O_TRUNC+O_CCSID
: S_IRGRP + S_IWGRP + S_IXGRP +
S_IRUSR + S_IWUSR + S_IXUSR
: 819);
callp close(fd);
fd = open(outputfile:O_WRONLY);
// decode InputData
declen = base64_decode(%addr(InputData : *DATA )
: len
: %addr(OutputData)
: %len(OutputData));
//Write it
callp write(fd: %addr(OutputData: *DATA): declen);
callp close(fd);
*Inlr = *On;
******IFS ==> variable pgm----------------------------***************
P IFS_file2Var b export
D IFS_file2Var pi 65535a varying
D pFile 256a value
*************************
D open pr 10i 0 extproc('open')
D filename * value options(*string)
D openflags 10i 0 value
D mode 10u 0 value options(*nopass)
D codepage 10u 0 value options(*nopass)
D creatcnvid 10u 0 value options(*nopass)
**************************
D read pr 10i 0 extproc('read')
D handle 10i 0 value
D buffer * value
D bytes 10u 0 value
***************
D close pr 10i 0 extproc('close')
D handle 10i 0 value
D data s 65535a
D bytesRead s 10i 0
D handle s 10i 0
D rc s 10i 0
D O_RDONLY c 1
D O_TEXTDATA c 16777216
*----------------------------------------------
handle = open(%trim(pFile): O_RDONLY+O_TEXTDATA);
if handle < 0;
// something is wrong
return '';
endif;
bytesRead = read(handle: %addr(data): %size(data));
if bytesRead <= 0;
return '';
endIf;
rc = close(handle);
return %trim(data);
P e
****************** End of data ****************************************
Comment