Ich hatte die letzten Tage überlegt, dass es nett wäre, wenn ich mal DEFLATE (RFC 1951) implementieren würde, also den Algorithmus hinter zlib (RFC 1950) und gzip (RFC 1952) sowie ZIP. Dazu wollte ich erstmal den Dekompressor schreiben, jedoch passt die Spec nicht zu den Testdaten die ich generiert habe.
Also, angenommen diese Daten:
Code: Alles auswählen
printf 'Blah blah blah blah blah!' | openssl zlib -e | xxd
# Python-zlib-Modul geht genauso
00000000: 789c 73ca 49cc 5048 c224 1401 6f19 0875 x.s.I.PH.$..o..u
Code: Alles auswählen
3.2.3. Details of block format
Each block of compressed data begins with 3 header bits
containing the following data:
first bit BFINAL
next 2 bits BTYPE
Note that the header bits do not necessarily begin on a byte
boundary, since a block does not necessarily occupy an integral
number of bytes.
BFINAL is set if and only if this is the last block of the data
set.
BTYPE specifies how the data are compressed, as follows:
00 - no compression
01 - compressed with fixed Huffman codes
10 - compressed with dynamic Huffman codes
11 - reserved (error)
Hier noch der Ausschnitt aus der zlib-Beschreibung, die ich als Referenz nutze.
Code: Alles auswählen
2.2. Data format
A zlib stream has the following structure:
0 1
+---+---+
|CMF|FLG| (more-->)
+---+---+
(if FLG.FDICT set)
0 1 2 3
+---+---+---+---+
| DICTID | (more-->)
+---+---+---+---+
+=====================+---+---+---+---+
|...compressed data...| ADLER32 |
+=====================+---+---+---+---+