summary refs log tree commit diff
path: root/crypto/src/util/zlib/ZOutputStream.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2016-05-26 20:58:36 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2016-05-26 20:58:36 +0700
commit3d68923d4ecb7379aebcdba65615524997460d02 (patch)
tree43be845d5901e934ffc0092c57e671bd1d8d5f8a /crypto/src/util/zlib/ZOutputStream.cs
parentremoved obsolete annotation (diff)
downloadBouncyCastle.NET-ed25519-3d68923d4ecb7379aebcdba65615524997460d02.tar.xz
Improve ZInputStream/ZOutputStream constructors
Diffstat (limited to 'crypto/src/util/zlib/ZOutputStream.cs')
-rw-r--r--crypto/src/util/zlib/ZOutputStream.cs28
1 files changed, 22 insertions, 6 deletions
diff --git a/crypto/src/util/zlib/ZOutputStream.cs b/crypto/src/util/zlib/ZOutputStream.cs

index d9f005f69..1633b2d8f 100644 --- a/crypto/src/util/zlib/ZOutputStream.cs +++ b/crypto/src/util/zlib/ZOutputStream.cs
@@ -42,7 +42,14 @@ namespace Org.BouncyCastle.Utilities.Zlib public class ZOutputStream : Stream { - private const int BufferSize = 512; + private static ZStream GetDefaultZStream(bool nowrap) + { + ZStream z = new ZStream(); + z.inflateInit(nowrap); + return z; + } + + private const int BufferSize = 512; protected ZStream z; protected int flushLevel = JZlib.Z_NO_FLUSH; @@ -55,9 +62,14 @@ namespace Org.BouncyCastle.Utilities.Zlib protected bool closed; public ZOutputStream(Stream output) - : this(output, null) - { - } + : this(output, false) + { + } + + public ZOutputStream(Stream output, bool nowrap) + : this(output, GetDefaultZStream(nowrap)) + { + } public ZOutputStream(Stream output, ZStream z) : base() @@ -67,12 +79,16 @@ namespace Org.BouncyCastle.Utilities.Zlib if (z == null) { z = new ZStream(); + } + + if (z.istate == null && z.dstate == null) + { z.inflateInit(); } this.output = output; + this.compress = (z.istate == null); this.z = z; - this.compress = false; } public ZOutputStream(Stream output, int level) @@ -86,9 +102,9 @@ namespace Org.BouncyCastle.Utilities.Zlib Debug.Assert(output.CanWrite); this.output = output; + this.compress = true; this.z = new ZStream(); this.z.deflateInit(level, nowrap); - this.compress = true; } public sealed override bool CanRead { get { return false; } }