Skip to content

Small compression unit that handles pure deflate, ZLIB and GZIP written in Free Pascal

License

Notifications You must be signed in to change notification settings

grahamegrieve/zflate

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zflate

This unit allows you to easily compress and decompress buffers and strings like in PHP. Main goal of this unit is to be as small as possible.

  • compiled demo is ~80 kB in size
  • adding unit to uses section increases binary size by ~45 kB, even less if you already use zlib units for other things

Status

Compression Decompression
FunctionFormatStatus
gzdeflate()DEFLATE
gzcompress()ZLIB
gzencode()GZIP
FunctionFormatStatus
gzinflate()DEFLATE
gzuncompress()ZLIB
gzdecode()GZIP
zdecompress()ANY

Usage

compressed := gzencode('some string');
decompressed := gzdecode(compressed);

Use zdecompress() to auto detect stream type and decompress:

compressed := gzencode('some string');
decompressed := zdecompress(compressed);

Functions

//compress whole buffer to DEFLATE at once
function gzdeflate(data: pointer; size: dword; var output: pointer; var outputsize: dword; level: dword=9): boolean;
//compress whole string to DEFLATE at once
function gzdeflate(str: string; level: dword=9): string;
//decompress whole DEFLATE buffer at once
function gzinflate(data: pointer; size: dword; var output: pointer; var outputsize: dword): boolean;
//decompress whole DEFLATE string at once
function gzinflate(str: string): string;

//compress whole buffer to ZLIB at once
function gzcompress(data: pointer; size: dword; var output: pointer; var outputsize: dword; level: dword=9): boolean;
//compress whole string to ZLIB at once
function gzcompress(str: string; level: dword=9): string;
//dempress whole ZLIB buffer at once
function gzuncompress(data: pointer; size: dword; var output: pointer; var outputsize: dword): boolean;
//dempress whole ZLIB string at once
function gzuncompress(str: string): string;

//compress whole buffer to GZIP at once
function gzencode(data: pointer; size: dword; var output: pointer; var outputsize: dword; level: dword=9; filename: string=''; comment: string=''): boolean;
//compress whole string to GZIP at once
function gzencode(str: string; level: dword=9; filename: string=''; comment: string=''): string;
//decompress whole GZIP buffer at once
function gzdecode(data: pointer; size: dword; var output: pointer; var outputsize: dword): boolean;
//decompress whole GZIP string at once
function gzdecode(str: string): string;

//try to detect buffer format and decompress it at once
function zdecompress(data: pointer; size: dword; var output: pointer; var outputsize: dword): boolean;
//try to detect string format and decompress it at once
function zdecompress(str: string): string;

zflatefiles

Additional unit to handle bigger files. Read & write & compress/decompress by chunks.

Status

Compression Decompression
FunctionFormatStatus
gzdeflate_file()DEFLATE
gzcompress_file()ZLIB
gzencode_file()GZIP
FunctionFormatStatus
gzinflate_file()DEFLATE
gzuncompress_file()ZLIB
gzdecode_file()GZIP

Functions

//compress a file to GZIP
function gzencode_file(src, dst: string; level: dword=9; filename: string=''; comment: string=''; progresscb: tzprogresscb=nil; resolution: dword=100): boolean;
//decompress a GZIP file
function gzdecode_file(src, dst: string; progresscb: tzprogresscb=nil; resolution: dword=100): boolean;  

A callback may be provided to these functions. Callback function may abort ongoing operation by returning false.

About

Small compression unit that handles pure deflate, ZLIB and GZIP written in Free Pascal

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Pascal 100.0%