Minimal ZIP file – part II 
       =============================
       
       
       This article is part of a series. 
       
 (DIR) Creating a valid ZIP-file
       - Use .NET’s DeflateStream 👈 
 (DIR) No dependencies (coding the DEFLATE algorithm)
 (DIR) Calculating the CRC-32
       
       Introduction 
       -------------
       
       
       In part 1 a valid ZIP-file was created using uncompressed data. To be more useful, data should be compressed. 
       
 (DIR) part 1
       
       The most simple way is the so-called DEFLATE algorithm 1 . DEFLATE is supported back to PKZIP 2.x. 
       
 (DIR) 1
       
       Compressing the data 
       ---------------------
       
       
       Using .NET’s DeflateStream it is easy to compress the data. I consider this a little bit of cheating, but it is a good starting point 2 . See also the next part to fix this. 
       
 (DIR) 2
 (DIR) next part
       
       It takes only a few modifications to our previous program to compress the data to a MemoryStream 3 and write it to the ZIP-file: 
       
 (DIR) 3
       
       Other than that, only a few modifications are needed when writing the headers: 
       
       - uncompressed size vs. compressed size 
       - compression method none vs. DEFLATE 
       
       Source code 
       ------------
       
       
       The modified code: 
       
       
       Zip2.cs 
       
 (DIR) Zip2.cs
       
       Next up 
       --------
       
       
       In the next part the dependency on System.IO.Compression.DeflateStream will be removed. 
       
 (DIR) next part
       ----------------------------------
       -  Wikipedia: Deflate  ↩︎  
       
       Wikipedia: Deflate  ↩︎ 
       
 (HTM) Deflate 
 (DIR) ↩︎
       -  Using ZipArchive would be the real cheat! ↩︎  
       
       Using ZipArchive would be the real cheat! ↩︎ 
       
 (DIR) ↩︎
       -  Ideally, write to the zip-stream directly, but that introduces chicken’n’egg issues since both compressed size and CRC are needed to write the file header and the directory . ↩︎  
       
       Ideally, write to the zip-stream directly, but that introduces chicken’n’egg issues since both compressed size and CRC are needed to write the file header and the directory . ↩︎ 
       
 (DIR) ↩︎
 (DIR) previous Minimal ZIP file – part I
       
 (DIR) next Minimal ZIP file – part III
       
       
       Related 
       --------
       
 (DIR) Gopher enabled
 (TXT) Goofy gopher (.svg) 
 (DIR) http2gopher
 (TXT) /img/fallback.svg (.svg) 
 (DIR) Data compression 101
 (TXT) /img/fallback.svg (.svg) 
 (DIR) [Talk] Datacompressie
 (TXT) bits (.svg) 
 (DIR) Delphi Tetris
 (IMG) Delphi Tetris (.png) 
 (DIR) PicoSearch - TF-IDF in 50 lines
 (TXT) /img/fallback.svg (.svg) 
 (DIR) Software engineering, een volwassen vak?
 (IMG) Boekje (.jpeg) 
 (DIR) Blaztris
 (TXT) /img/fallback.svg (.svg) 
 (DIR) Upgrade application without source code
 (TXT) Bits (.svg) 
 (DIR) Colossus PoC
 (IMG) screenshot of colossus visualiser and malfunction controller (.png)