ZLibCompress

From SCAR Divi Manual
Revision as of 16:24, 9 February 2012 by Freddy (talk | contribs) (Created page with "==Definition== <source lang="scar" lines="false"> function ZLibCompress(const Str: AnsiString): AnsiString; </source> ==Availability== SCAR Divi 3.31 > Current ==Description== ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Definition

function ZLibCompress(const Str: AnsiString): AnsiString;

Availability

SCAR Divi 3.31 > Current

Description

Compresses a given string Str using the [1] compression library. A ZLib compressed string can be decompressed with ZLibDecompress.

Example

var
  Str, Compressed, Encoded: AnsiString;

begin
  Str := 'Lorem ipsum dolor sit amet, consectetur a dipiscing elit. Duis male' +
    'suada, lorem ut pellentesque vehicula, urna nibh ultricies eros, ut hend' +
    'rerit nisi mauris ut massa. Phasellus sed velit velit. Nullam id nunc nu' +
    'lla, tristique dignissim libero. Cras viverra magna quis sapien aliquam ' +
    'egestas. Curabitur pellentesque molestie odio, et placerat metus auctor ' +
    'id. Mauris auctor euismod turpis sit amet interdum. Nam molestie nunc le' +
    'ctus. Maecenas aliquam bibendum ipsum, vel cursus elit tincidunt in. Don' +
    'ec metus sapien, egestas in tempor eget, malesuada non leo. Cum sociis n' +
    'atoque penatibus et magnis dis parturient montes, nascetur ridiculus mus' +
    '. In hac habitasse platea dictumst. Mauris vel aliquam enim. Etiam ferme' +
    'ntum tincidunt nisl in placerat. Integer congue convallis nisl, ut eleif' +
    'end elit dictum quis.'#13#10#13#10 +
    'Fusce vitae ultricies lorem. Aenean ultricies pretium massa eget feugiat' +
    '. Cras at tincidunt ligula. Suspendisse accumsan blandit eros, ac bibend' +
    'um sem elementum porttitor. Mauris vel orci eget massa dapibus eleifend ' +
    'a ultrices purus. Sed fermentum mi id est pellentesque tincidunt. Duis p' +
    'orttitor interdum nunc in pretium. Donec sit amet ipsum vel nulla elemen' +
    'tum ullamcorper quis id erat. Pellentesque arcu eros, aliquet porttitor ' +
    'molestie ac, pharetra vitae libero. Etiam sed quam mi. Phasellus nec nis' +
    'i ac purus ultrices pulvinar sed et quam. Nullam magna nisl, elementum i' +
    'n tempus in, gravida eu neque. Sed a leo ipsum. Nulla vulputate ante dol' +
    'or. Etiam dapibus aliquam laoreet. Cras pulvinar, augue id interdum laci' +
    'nia, turpis nunc euismod arcu, sit amet imperdiet nunc mi in diam.';
  WriteLn('Original length: ' + IntToStr(Length(Str)));
  Compressed := ZLibCompress(Str);
  WriteLn('Length after compression: ' + IntToStr(Length(Compressed)));
  Encoded := StrToBase64(Compressed);
  WriteLn('Length after compression and encoding: ' + IntToStr(Length(Encoded)));
end.

Output:

Original length: 1598
Length after compression: 752
Length after compression and encoding: 1004

See Also