Example #1
0
 internal DeflateStream(Stream compressedStream, CompressionMode mode, bool leaveOpen, bool gzip)
 {
     if (compressedStream == null)
     {
         throw new ArgumentNullException("compressedStream");
     }
     if (mode != CompressionMode.Compress && mode != CompressionMode.Decompress)
     {
         throw new ArgumentException("mode");
     }
     this.data        = GCHandle.Alloc(this);
     this.base_stream = compressedStream;
     this.feeder      = ((mode != CompressionMode.Compress) ? new DeflateStream.UnmanagedReadOrWrite(DeflateStream.UnmanagedRead) : new DeflateStream.UnmanagedReadOrWrite(DeflateStream.UnmanagedWrite));
     this.z_stream    = DeflateStream.CreateZStream(mode, gzip, this.feeder, GCHandle.ToIntPtr(this.data));
     if (this.z_stream == IntPtr.Zero)
     {
         this.base_stream = null;
         this.feeder      = null;
         throw new NotImplementedException("Failed to initialize zlib. You probably have an old zlib installed. Version 1.2.0.4 or later is required.");
     }
     this.mode      = mode;
     this.leaveOpen = leaveOpen;
 }