/// <summary>Releases the unmanaged resources used by the <see cref="T:System.IO.Compression.DeflateStream" /> and optionally releases the managed resources.</summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (disposing && !this.disposed) { this.disposed = true; IntPtr intPtr = this.z_stream; this.z_stream = IntPtr.Zero; int result = 0; if (intPtr != IntPtr.Zero) { result = DeflateStream.CloseZStream(intPtr); } this.io_buffer = null; if (!this.leaveOpen) { Stream stream = this.base_stream; if (stream != null) { stream.Close(); } this.base_stream = null; } DeflateStream.CheckResult(result, "Dispose"); } if (this.data.IsAllocated) { this.data.Free(); this.data = default(GCHandle); } base.Dispose(disposing); }
/// <summary>Flushes the contents of the internal buffer of the current stream object to the underlying stream.</summary> /// <exception cref="T:System.ObjectDisposedException">The stream is closed.</exception> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" /> /// </PermissionSet> public override void Flush() { if (this.disposed) { throw new ObjectDisposedException(base.GetType().FullName); } if (this.CanWrite) { int result = DeflateStream.Flush(this.z_stream); DeflateStream.CheckResult(result, "Flush"); } }
private unsafe void WriteInternal(byte[] array, int offset, int count) { if (count == 0) { return; } int result; fixed(byte *ptr = ref (array != null && array.Length != 0)?ref array[0] : ref *null) { IntPtr buffer = new IntPtr((void *)(ptr + offset)); result = DeflateStream.WriteZStream(this.z_stream, buffer, count); } DeflateStream.CheckResult(result, "WriteInternal"); }