protected override void Dispose(bool disposing) { if (disposing) { GC.SuppressFinalize(this); } native?.Dispose(disposing); if (disposing && !disposed) { disposed = true; if (!leaveOpen) { Stream st = base_stream; if (st != null) { st.Close(); } base_stream = null; } } base.Dispose(disposing); }
public static DeflateStreamNative Create(Stream compressedStream, CompressionMode mode, bool gzip) { var dsn = new DeflateStreamNative(); dsn.data = GCHandle.Alloc(dsn); dsn.feeder = mode == CompressionMode.Compress ? new UnmanagedReadOrWrite(UnmanagedWrite) : new UnmanagedReadOrWrite(UnmanagedRead); dsn.z_stream = CreateZStream(mode, gzip, dsn.feeder, GCHandle.ToIntPtr(dsn.data)); if (dsn.z_stream.IsInvalid) { dsn.Dispose(true); return(null); } dsn.base_stream = compressedStream; return(dsn); }
protected override void Dispose(bool disposing) { native.Dispose(disposing); if (disposing && !disposed) { disposed = true; if (!leaveOpen) { Stream st = base_stream; if (st != null) { st.Close(); } base_stream = null; } } base.Dispose(disposing); }
public static DeflateStreamNative Create (Stream compressedStream, CompressionMode mode, bool gzip) { var dsn = new DeflateStreamNative (); dsn.data = GCHandle.Alloc (dsn); dsn.feeder = mode == CompressionMode.Compress ? new UnmanagedReadOrWrite (UnmanagedWrite) : new UnmanagedReadOrWrite (UnmanagedRead); dsn.z_stream = CreateZStream (mode, gzip, dsn.feeder, GCHandle.ToIntPtr (dsn.data)); if (dsn.z_stream == IntPtr.Zero) { dsn.Dispose (true); return null; } dsn.base_stream = compressedStream; return dsn; }