Recent

Author Topic: paszlib. Feature request on work with buffers  (Read 839 times)

LemonParty

  • Hero Member
  • *****
  • Posts: 537
paszlib. Feature request on work with buffers
« on: May 19, 2026, 12:09:52 pm »
I am asking to add method, functions to work with buffers to that library.

They should look like this:
Code: Pascal  [Select][+][-]
  1. {decompress pointed file to buffer}
  2. TUnZipper.UnZipToBuffer(AZipFileName: RawByteString; var OutBuf);
  3.  
  4. {compress buffer with BufSize to OutBuf, return actual size of OutBuf}
  5. function Zip(const Buf; BufZize: SizeUInt; var OutBuf): SizeUInt;
  6. {decompress buffer with BufSize to OutBuf, return actual size of OutBuf}
  7. function UnZip(const Buf; BufZize: SizeUInt; var OutBuf): SizeUInt;
  8.  
  9. {compress given string and return it compressed version as a string}
  10. function Zip(Uncompressed: String): String;
  11. {decompress given string and return it original value}
  12. function UnZip(Compressed: String): String;
Important note: Zip and UnZip of buffers should directly write their result to buffer (or use TExposedMemoryStream(Stream).SetPointer to point OutBuf). This method and functions will simplify work with this library.
« Last Edit: May 19, 2026, 12:16:06 pm by LemonParty »
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

Tomxe

  • Full Member
  • ***
  • Posts: 107
Re: paszlib. Feature request on work with buffers
« Reply #1 on: May 19, 2026, 01:31:03 pm »
Are you sure you want Zip, not Deflate? Zip is an archive, it can contain multiple files packed with many different algorithms. If you want Zip than there should be a filename argument in that functions.

LemonParty

  • Hero Member
  • *****
  • Posts: 537
Re: paszlib. Feature request on work with buffers
« Reply #2 on: May 19, 2026, 01:41:24 pm »
Yes, Deflate would be nice.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

Tomxe

  • Full Member
  • ***
  • Posts: 107
Re: paszlib. Feature request on work with buffers
« Reply #3 on: May 19, 2026, 02:22:27 pm »
Code: Pascal  [Select][+][-]
  1.   function Zip(Uncompressed: RawByteString; Filename: String): RawByteString;
  2.   function UnZip(Compressed: RawByteString; Filename: String): RawByteString;
  3.   function Deflate(Uncompressed: RawByteString): RawByteString;
  4.   function Inflate(Compressed: RawByteString): RawByteString;

LemonParty

  • Hero Member
  • *****
  • Posts: 537
Re: paszlib. Feature request on work with buffers
« Reply #4 on: May 19, 2026, 03:38:17 pm »
Nice. Thank you.
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

LemonParty

  • Hero Member
  • *****
  • Posts: 537
Re: paszlib. Feature request on work with buffers
« Reply #5 on: May 19, 2026, 05:16:13 pm »
I have few questions:
1. Is there a way to find the size of uncompressed fragment from compressed string before doing actual decompression?
2. What is the worst case for compression? I mean if data wasn't compress at all how many bytes it will grow in size compare to original size?
Lazarus v. 4.99. FPC v. 3.3.1. Windows 11

Tomxe

  • Full Member
  • ***
  • Posts: 107
Re: paszlib. Feature request on work with buffers
« Reply #6 on: May 19, 2026, 05:46:46 pm »
Added:

Code: Pascal  [Select][+][-]
  1. function Zip(const Buf; BufZize: SizeUInt; Filename: String; var OutBuf): SizeUInt; overload;

Tomxe

  • Full Member
  • ***
  • Posts: 107
Re: paszlib. Feature request on work with buffers
« Reply #7 on: May 19, 2026, 05:48:36 pm »
I have few questions:
1. Is there a way to find the size of uncompressed fragment from compressed string before doing actual decompression?
2. What is the worst case for compression? I mean if data wasn't compress at all how many bytes it will grow in size compare to original size?

1. Yes, but you would need to parse ZIP file. I don't think there is a function to do that.
2. No idea. You might try googling that.

Thausand

  • Hero Member
  • *****
  • Posts: 560
Re: paszlib. Feature request on work with buffers
« Reply #8 on: May 19, 2026, 06:11:15 pm »
If you want Zip than there should be a filename argument in that functions.
Why ?

Any file can have store in memory (example stream). Then is need for parse zip file format. File format is documented for many zip type (pkzip, zlib etc). some is document RFC other is document other resource.
A docile goblin always follow HERMES.md

Tomxe

  • Full Member
  • ***
  • Posts: 107
Re: paszlib. Feature request on work with buffers
« Reply #9 on: May 19, 2026, 07:45:34 pm »
Why ?

Any file can have store in memory (example stream). Then is need for parse zip file format. File format is documented for many zip type (pkzip, zlib etc). some is document RFC other is document other resource.
I am not talking about saving a zip archive to disk under a given filename. I am talking about adding data to a ZIP archive- such data needs a filename, for example test.txt:

Thausand

  • Hero Member
  • *****
  • Posts: 560
Re: paszlib. Feature request on work with buffers
« Reply #10 on: May 19, 2026, 09:57:33 pm »
I am not talking about saving a zip archive to disk under a given filename. I am talking about adding data to a ZIP archive- such data needs a filename, for example test.txt:
Ah, that my wrong. I make apology.

 make confuse because argument is name filename. TZipentry is name archivefilename and diskfilename for make distinct zipfilename.

But name is no matter ? it can be any thing ? (e.g. generate random filename ?).
A docile goblin always follow HERMES.md

Tomxe

  • Full Member
  • ***
  • Posts: 107
Re: paszlib. Feature request on work with buffers
« Reply #11 on: May 20, 2026, 09:03:49 am »
But name is no matter ? it can be any thing ? (e.g. generate random filename ?).
Sure, it can be anything. But it can't be empty if you want to save that ZIP on disk and unpack it with programs like 7zip, Winrar, PeaZip.

Tomxe

  • Full Member
  • ***
  • Posts: 107
Re: paszlib. Feature request on work with buffers
« Reply #12 on: May 20, 2026, 09:19:12 am »
Here's something that also might interest you:
https://github.com/Xelitan/Various-Free-Pascal-TStreams/

Code: Pascal  [Select][+][-]
  1. var Bytes: TBytes;
  2. begin
  3. Stream := TPointerStream.Create(@Bytes[0], Length(Bytes));

This lets you use TBytes, arrays, strings and PBytes without copying as TStreams.

Thaddy

  • Hero Member
  • *****
  • Posts: 19273
  • Glad to be alive.
Re: paszlib. Feature request on work with buffers
« Reply #13 on: May 20, 2026, 10:06:27 am »
@Tomxe
Ouch, that can not be correct: it will work but is probably not necessary and the wrong notation.
I will look at it and hopefully can come up with better syntax.
(Again, I am encouraging you, not criticize)
« Last Edit: May 20, 2026, 10:09:15 am by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

Tomxe

  • Full Member
  • ***
  • Posts: 107
Re: paszlib. Feature request on work with buffers
« Reply #14 on: May 20, 2026, 11:43:10 am »
You mean the PointerStream? I am no expert on pointers but it seems okay to me.

 

TinyPortal © 2005-2018