- save space or bandwidth by compressing data.
- I/O system - 2 mthds for compressing data: GZIP, DEFLATE.
- both mthds - lmtd to compress 4GB of uncompressed data.
- GZipStream, DeflateStream classes.
- GZipStream Vs DeflateStream - GZIP has header. Header might be useful when decrompressing with gzip tool. If internal - DeflateStream file slightly smaller. If external - gzip, as may need header.
- CompressionStreams - write to another stream, not a resource (e.g. a file or memory).
- CompressionStream - wraps the stream that contains (or will contain) compressed data.
- 1. Open file to be compressed + file to be written to - FileStream sourceFile = File.OpenRead(inFileName);
- 2. wrap outgoing stream - GZipStream compStream = new GZipStream(destFile, CompressionMode.Compress);
- 3. read data from source & feed -> compression stream -
- int theByte = sourceFile.ReadByte();
- while (theByte != -1)
- {
- compStream.WriteByte.((byte)theByte);
- theByte = sourceFile.ReadByte();
- }
No comments:
Post a Comment