summary refs log tree commit diff
path: root/crypto/src/util/zlib/ZInputStream.cs
diff options
context:
space:
mode:
authorDavid Hook <dgh@bouncycastle.org>2016-12-28 22:02:41 +1100
committerDavid Hook <dgh@bouncycastle.org>2016-12-28 22:02:41 +1100
commitd21cb9eeb630b0b81978a907c08cc88cdd650cd7 (patch)
treeadffc74ed7019ef8cf89691960ff211b88f6c3d2 /crypto/src/util/zlib/ZInputStream.cs
parentfixed head of loop to use primitive type. (diff)
parentFix carry propagation bug in Nat???.Square methods (diff)
downloadBouncyCastle.NET-ed25519-d21cb9eeb630b0b81978a907c08cc88cdd650cd7.tar.xz
Merge branch 'master' of bcgit@git.bouncycastle.org:bc-csharp.git
Diffstat (limited to 'crypto/src/util/zlib/ZInputStream.cs')
-rw-r--r--crypto/src/util/zlib/ZInputStream.cs47
1 files changed, 38 insertions, 9 deletions
diff --git a/crypto/src/util/zlib/ZInputStream.cs b/crypto/src/util/zlib/ZInputStream.cs

index 4b7351555..434fe95c8 100644 --- a/crypto/src/util/zlib/ZInputStream.cs +++ b/crypto/src/util/zlib/ZInputStream.cs
@@ -42,9 +42,16 @@ namespace Org.BouncyCastle.Utilities.Zlib public class ZInputStream : 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 = new ZStream(); + protected ZStream z; protected int flushLevel = JZlib.Z_NO_FLUSH; // TODO Allow custom buf protected byte[] buf = new byte[BufferSize]; @@ -62,24 +69,46 @@ namespace Org.BouncyCastle.Utilities.Zlib } public ZInputStream(Stream input, bool nowrap) + : this(input, GetDefaultZStream(nowrap)) + { + } + + public ZInputStream(Stream input, ZStream z) + : base() { Debug.Assert(input.CanRead); - this.input = input; - this.z.inflateInit(nowrap); - this.compress = false; - this.z.next_in = buf; + if (z == null) + { + z = new ZStream(); + } + + if (z.istate == null && z.dstate == null) + { + z.inflateInit(); + } + + this.input = input; + this.compress = (z.istate == null); + this.z = z; + this.z.next_in = buf; this.z.next_in_index = 0; this.z.avail_in = 0; } - public ZInputStream(Stream input, int level) + public ZInputStream(Stream input, int level) + : this(input, level, false) + { + } + + public ZInputStream(Stream input, int level, bool nowrap) { Debug.Assert(input.CanRead); this.input = input; - this.z.deflateInit(level); - this.compress = true; + this.compress = true; + this.z = new ZStream(); + this.z.deflateInit(level, nowrap); this.z.next_in = buf; this.z.next_in_index = 0; this.z.avail_in = 0;