GZIP / deflate Streams mit Free Pascal GZIP bzw. deflate Streams mit Free Pascal Komprimierte Datenübertragung Unterschiede Deflate / GZip GZip und deflate(ZLib) unterscheidet sich lediglich durch den Header und die Checksumme, denn beide benutzt im Eigentlichen die selbe Methode zum Komprimieren (deflate = Luft heraus lassen :) ) Unter Free Pascal steht das Package paszlib zur Verfügung, welches die benötigten Funktionen zum Behandeln von deflated Blöcken zur Verfügung stellt. Mit Hilfe dieser Funktionen lassen sich alle benötigten Funktionen  deflate (raw), GZip, ZLib, inflate (raw) und ZUncompressStream erzeugen. ZUncompessStream übernimmt die Identifizierung des Typs und nutzt die Funktion inflate zum entpacken des deflated Teils. Die Routinen sollten dazu in der Lage sein sowohl deflated (ZLib) und gziped Streams zum Versand zu erzeugen, als auch Empfangene Streams dieser Formate wieder zu entpacken! Aufbau Deflate (ZLib): ZLIB Compressed Data Format Specification("https://www.rfc-editor.org/rfc/rfc1950") * 2 bytes Defines the compression mode * 1 byte $78 CMF Compression Method and flags "deflate" compression method with a window size up to 32K * 1 byte FLG * bit 0-4 FCHECK (check bits for CMF and FLG) * bit 5 FDICT (preset dictionary) * bit 6-7 FLEVEL (compression level) Examples: (List of file signatures("https://en.wikipedia.org/wiki/List_of_file_signatures")) * $01 No Compression (no preset dictionary) * $5E Best speed (no preset dictionary) * $9C Default Compression (no preset dictionary) * $DA Best Compression (no preset dictionary) * $20 No Compression (with preset dictionary) * $7D Best speed (with preset dictionary) * $BB Default Compression (with preset dictionary) * $F9 Best Compression (with preset dictionary) * 4 bytes DICTID Present only when FLG.FDICT is set. * deflated stream * 4 bytes adler32 checksum GZip: GZIP file format specification("https://www.ietf.org/rfc/rfc1952.txt") * 2 bytes $1f $8b  (IDentification) * 1 byte $08 Compression Method = deflate * 1 byte $00 FLaGs * bit 0   FTEXT - indicates file is ASCII text (can be safely ignored) * bit 1   FHCRC - there is a CRC16 for the header immediately following the header * bit 2   FEXTRA - extra fields are present * bit 3   FNAME - the zero-terminated filename is present. encoding; ISO-8859-1. * bit 4   FCOMMENT - a zero-terminated file comment is present. encoding: ISO-8859-1 * bit 5-7   reserved * 4 bytes $00000000 Modification TIME = no time stamp is available * 1 byte $00 eXtra FLags * 00 - default compression * 02 - compressor used maximum compression, slowest algorithm * 04 - compressor used fastest algorithm * 1 byte $0b Operating System = NTFS filesystem (NT)  for textfiles (line ending) * 00 - FAT filesystem (MS-DOS, OS/2, NT/Win32) * 01 - Amiga 02 - VMS (or OpenVMS) * 03 - Unix * 04 - VM/CMS * 05 - Atari TOS * 06 - HPFS filesystem (OS/2, NT) * 07 - Macintosh * 08 - Z-System * 09 - CP/M * 0A - TOPS-20 * 0B - NTFS filesystem (NT) * 0C - QDOS * 0D - Acorn RISCOS * FF - unknown * deflated stream * crc32 checksum * input size GZIPUtils.pas("https://www.gocher.me/code/gziputils.pas") Beispiel: TestGzip.pas("https://www.gocher.me/code/TestGzip.pas")