[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: AW: HTTPAPI / call webservice in base64binary-code
Hello Marcus,
> To get a result which looks a little bit of an example I have i must
> first convert the string into ASCII-code. Is it right? But as say the
> result isn't the same. Could the different codepage ( i'm working on
> a "german"-machine ) the reason?
Ummm... base64 has nothing to do with codepage. The purpose of base64
is to take the input binary values and convert them to invariant text so
that when it's decoded, you'll get the exact same binary values you
started with.
If you want your data to be in a particular codepage, then YOU must put
it into that codepage before you convert it to base64.
Your method of doing this seems extremely strange to me. You read data
from an IFS file, then convert each byte individually to ASCII using the
QASCII translation table.
My thoughts:
a) Why loop through the data and convert it one byte at a time?
Wouldn't it be more efficient to convert all 54 bytes at once? Isn't
one call to a program faster than 54 calls?
b) Why do you use the QASCII translation table? That method doesn't let
you specify which codepage you use for input, or which one you use for
output. Does it actually yield the correct code points? I bet it doesn't.
c) Isn't the IFS file in the correct CCSID to begin with? If not, then
why? It seems weird to take a PC-style file and manually convert it to
ASCII. Shouldn't it already be in ASCII? If not, why not ask the
system to convert it for you? What's the point of using a hack like
QDCXLATE?
d) You only read fixed-length data from the file. If your file isn't an
even multiple of 54 bytes, you'll discard the remainder of the file. Is
that really what you wanted to do??!
I would've made my read loop look more like the following code. Pay
close attention to the lengths used -- you want to encode any data you
read, not only if it's 54 bytes long. You also want to use the length
read, not the size of the field, when you do the encoding. Likewise,
you want to write the length after encoding, not the size of the field,
because they may not be the same!
C eval len = read( fdO
C : %addr(rddata)
C : %size(rddata))
C DOW len > 0
C EVAL len3 = Base64_encode( %addr(rddata)
C : len
C : %addr(wrdataN)
C : %size(wrdataN))
c callp write( fdN
C : %addr(wrdataN)
C : len3 )
C eval len = read( fdO
C : %addr(rddata)
C : %size(rddata))
C enddo
Notice that I removed the call to QDCXLATE, because I expect the IFS
file to already be in the correct code page. If it's not, but the file
has been tagged with the appropriate CCSID, you can tell the open() API
to perform the translation. If you want to do it manually, I'd
recommend the iconv() API, as it lets you specify a from/to CCSID
instead of picking a random table like QASCII.
Another (perhaps easier) solution is to use the CPY CL command to
convert it. For example:
CPY OBJ('/path/to/inputfile') TOOBJ('/path/to/outputfile') +
FROMCCSID(273) TOCCSID(819) DTAFMT(*TEXT)
The QDCXLATE API will work -- but you have to find the right table.
It's very difficult to find the right table for the right CCSIDs in my
experience, so I always use iconv() in any application that's more than
a toy.
If you do decide to use QDCXLATE, don't call it individually for each
byte. Instead, pass the full buffer (the entire 54 bytes) in one call.
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------