Thursday, 13 September 2007

Lesson 3: Compressing Streams

Compression - useful in real-world projects to save space or bandwidth. .NF supports 2 new stream classes that can compress data.
  • GZIP & DEFLATE - 2 mthds inside .NF. Use industry-std compression algorithms. No intellectual-property issues.
  • size limit - can compress upto 4GB of uncompressed data.
  • said comp. mthds exposed by .NF as GZipStream() & DeflateStream().
  • gzip or DEFLATE? - GZIP allows for headers for xtra info. Thus if internal use DefalteStream - slightly smaller but if distributing externally use GZIP.
  • GZipStream() - allows comp.

How to Compress Data with a Compression Stream

  • Compression streams don't write to a resource (e.g. a file, memory) - they write to other streams.
  • typical scenario - read an existing file & write to a new compressed version of the file.
  • GZipStream compStream = new GZipStream(destFile, CompressionMode.Compress) - a compression stream wraps the stream that contains (or will contain) compressed data.

No comments: