BASE64 Decode and Blanks

Discussions relating to writing software in ILE RPG (RPG IV). This includes both fixed and free format RPG.
Post Reply
San_jays
Posts: 5
Joined: Fri Jul 26, 2024 5:18 pm

BASE64 Decode and Blanks

Post 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;
jonboy49
Posts: 242
Joined: Wed Jul 28, 2021 8:18 pm

Re: BASE64 Decode and Blanks

Post 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.
San_jays
Posts: 5
Joined: Fri Jul 26, 2024 5:18 pm

Re: BASE64 Decode and Blanks

Post by San_jays »

Thanks @jonboy49. It worked, I was just testing a POC, and I will be -redesigning it!
Post Reply