Page 1 of 1

BASE64 Decode and Blanks

Posted: Mon Mar 17, 2025 7:44 pm
by San_jays
Hello,

I am running into an issue with BASE64_DECODE, it is adding leading blanks before the first line. The string 'JVBERi0xLjQKMyAwIG9iago8PC9UeXBlIC9QYQ==' when decoded and written to the IFS directory add 3 extra spaces before the first line.

Any advice here would be great. As the string starts with spaces the printer throws the error invalid XREF when sent to print.

%PDF-1.4
3 0 obj
<</Type

H DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR('BASE64')
D PDFin s 100A varying
D PDFLen s 10U 0
D PDFOut s 164536A varying
DRW c 6
DR c 4
DOWNER c 64
D ifsPathName s 500a varying
d fd s 10i 0

/copy base64/qrpglesrc,base64_h
/copy base64/qrpglesrc,ifsio_h

pdfin = 'JVBERi0xLjQKMyAwIG9iago8PC9UeXBlIC9QYQ==';
pdfLen= base64_decode(%addr(pdfin:*data):
%len(pdfin):
%addr(pdfout:*data): %size(pdfout));
ifspathname = '/home/mohapaj/test.pdf';
fd = open( ifsPathName
: O_CREAT + O_WRONLY + O_INHERITMODE
+O_CCSID
: RW*OWNER + R
: 819 //same with other CCSID as well (1208)
:0
);
callp write(fd: %addr(pdfout): PDFLEN);
callp close(fd);
*INLR = *on;
RETURN;

Re: BASE64 Decode and Blanks

Posted: Mon Mar 17, 2025 8:20 pm
by jonboy49
Looks to me as if

Code: Select all

callp write(fd: %addr(pdfout): PDFLEN);
Should be

Code: Select all

callp write(fd: %addr( pdfout : *Data ): PDFLEN);
Without that you are writing the varlen's length as part of the data and it is probably translating as blanks.

P.S. Why are you bothering to code CallP? It is not needed.

Re: BASE64 Decode and Blanks

Posted: Tue Mar 18, 2025 5:10 pm
by San_jays
Thanks @jonboy49. It worked, I was just testing a POC, and I will be -redesigning it!