Recent

Author Topic: fcl - ascii85 issues  (Read 370 times)

ama

  • Guest
fcl - ascii85 issues
« on: November 01, 2025, 02:26:34 pm »
hello,

it seems to me that TASCII85EncoderStream is bugged, it produces different output each time invoked.
given the string "test", each time invoked i get different 5-byte long ascii. (5 bytes is the correct output length for 4 bytes input, but the ascii it produces is incorrect)
side note: fcl documentation for TASCII85EncoderStream does not mention what variant of ascii85 encoding is used.

also note that i mainly do procedural programming, and i seriously know nothing about OOP; despite that i still believe my code is correct:

Code: Pascal  [Select][+][-]
  1. function EncodeAscii85(aData: String): String;
  2. var
  3.   asciiStream: TStringStream;
  4.   asciiEncoder: TASCII85EncoderStream;
  5.   asciiString: String;
  6.  
  7. begin
  8.   asciiStream := TStringStream.Create;
  9.   asciiEncoder := TASCII85EncoderStream.Create(asciiStream);
  10.  
  11.   asciiEncoder.Write(aData, aData.Length);
  12.   asciiEncoder.Destroy;
  13.  
  14.   asciiString := asciiStream.DataString;
  15.   asciiStream.Destroy;
  16.  
  17.   EncodeAscii85 := asciiString;
  18. end;
« Last Edit: November 01, 2025, 02:32:25 pm by ama »

korba812

  • Sr. Member
  • ****
  • Posts: 499
Re: fcl - ascii85 issues
« Reply #1 on: November 01, 2025, 02:39:07 pm »
No, your code isn't quite right. The first parameter of "Write" method is an untyped constant, so you need to specify the first character of string.

Code: Pascal  [Select][+][-]
  1. asciiEncoder.Write(aData[1], aData.Length);
  2.  

See:
https://www.freepascal.org/docs-html/ref/refsu70.html

ama

  • Guest
Re: fcl - ascii85 issues
« Reply #2 on: November 01, 2025, 02:45:30 pm »
thank you, i never used untyped variables.

from https://www.freepascal.org/docs-html/ref/refsu70.html
Quote
The compiler simply passes the address of the passed variable to the routine, so all that is available in the called routine is an address, with no type information attached to it. This is also true for const parameters.

now it works perfectly fine, and from the output i can tell that the implementation is using the original ascii85 encoding scheme.

 

TinyPortal © 2005-2018