Hello:
I'm trying to use ascii85 packages to decode/encode strings. But I get
this weird results:
--
Original Plain: 123456
Correct Encoded: <~0etOA2)Y~>
Encode 123456 = <~0etOA
Decode <~0etOA = 1234
Decode <~0etOA2)Y~> = 123456
--
It looks like decoder stops reading somewhere.
I'm using almost a verbatim copy of the packages example, but replacing
TFileStreams by TStringStreams:
Here is the code,
-
program Project1;
uses sysutils,ascii85,classes;
function Encode85(Plain: String): String;
var
StrmIn,StrmOut:TStringStream;
StrmEnc85:TASCII85EncoderStream;
begin
StrmIn:=TStringStream.Create(Plain);
try
StrmOut:=TStringStream.Create('');
try
StrmEnc85:=TAscii85EncoderStream.Create(StrmOut,72,True);
try
StrmEnc85.CopyFrom(StrmIn,0);
Result:=StrmOut.DataString;
finally
StrmEnc85.Free;
end;
finally
StrmOut.Free;
end;
finally
StrmIn.Free;
end;
end;
function Decode85(Encoded: string): string;
var
StrmIn,StrmOut:TStringStream;
StrmDec85:TASCII85DecoderStream;
buf:array [1..16] of byte;
Count: LongInt;
begin
StrmIn:=TStringStream.Create(Encoded);
StrmDec85:=TASCII85DecoderStream.Create(StrmIn);
try
StrmOut:=TStringStream.Create('');
try
Repeat
Count:=StrmDec85.Read(Buf,SizeOf(Buf));
If Count>0 then
StrmOut.WriteBuffer(Buf,Count);
Until (Count