Re: [fpc-pascal] Asci85

2016-09-17 Thread Santiago A.
El 16/09/2016 a las 15:01, José Mejuto escribió:
>
> Maybe there is something wrong in ASCII85 encoder, but this code is
> wrong, it should be something like:
>
>   try
> StrmEnc85.CopyFrom(StrmIn,0);
> StrmEnc85.Free;
> Result:=StrmOut.DataString;
>   finally
>
> Because stream must be flushed before extracting result and the flush
> is performed in the destroy. .
>

That's right.
 
Solved! Thanks!


-- 
Saludos

Santiago A.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Asci85

2016-09-16 Thread José Mejuto

El 16/09/2016 a las 10:16, Santiago A. escribió:

Hello,


 StrmEnc85:=TAscii85EncoderStream.Create(StrmOut,72,True);
 try
   StrmEnc85.CopyFrom(StrmIn,0);
   Result:=StrmOut.DataString;
 finally
   StrmEnc85.Free;


Maybe there is something wrong in ASCII85 encoder, but this code is 
wrong, it should be something like:


  try
StrmEnc85.CopyFrom(StrmIn,0);
StrmEnc85.Free;
Result:=StrmOut.DataString;
  finally

Because stream must be flushed before extracting result and the flush is 
performed in the destroy.


Saludos!.

--

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Asci85

2016-09-16 Thread Santiago A.
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