Exemplo n.º 1
0
            }             // func ReadStreamData

            private static (string hashName, byte[] hashValue) CopyData(bool shouldDeflate, Stream srcStream, byte[] buf, int readed, Stream dstStream)
            {
                // pack destination stream
                var dst = shouldDeflate
                                        ? new GZipStream(dstStream, CompressionMode.Compress, true)
                                        : dstStream;

                using (var dstHashStream = new HashStream(dst, HashStreamDirection.Write, false, SHA256.Create()))
                {
                    try
                    {
                        // copy stream into file
                        dstHashStream.Write(buf, 0, readed);
                        srcStream.CopyTo(dst);
                    }
                    finally
                    {
                        dstHashStream.Flush();
                        dstHashStream.Dispose();
                    }

                    dstHashStream.Close();

                    return("SHA2_256", dstHashStream.HashSum);
                }
            }             // func CopyData
Exemplo n.º 2
0
        public void TestHashStream()
        {
            var hash       = Create();
            var stream     = new MemoryStream();
            var hashStream = new HashStream <THash>(stream, hash);

            Assert.AreEqual(stream.CanRead, hashStream.CanRead);
            Assert.AreEqual(stream.CanWrite, hashStream.CanWrite);
            Assert.AreEqual(stream.CanSeek, hashStream.CanSeek);
            stream.Write(new byte[10], 0, 10);
            Assert.AreEqual(stream.Position, hashStream.Position);
            hashStream.Position = 0;
            Assert.AreEqual(0, hashStream.Position);
            Assert.AreEqual(stream.Position, hashStream.Position);
            hashStream.SetLength(5);
            Assert.AreEqual(stream.Length, hashStream.Length);
            hashStream.Flush();
            hashStream.Seek(1, SeekOrigin.Begin);
            Assert.AreEqual(1, hashStream.Position);
            Assert.AreEqual(stream.Position, hashStream.Position);
        }
Exemplo n.º 3
0
 public override void Flush()
 {
     HashStream.Flush();
     base.Flush();
 }