async Task <bool> ExtractPartAndValidate(PartialZipDownload part, Stream partInputStream, string cacheDirectory) { string fileHash = null; var outputPath = GetOutputPath(cacheDirectory, part); using (var iis = new System.IO.Compression.DeflateStream(partInputStream, System.IO.Compression.CompressionMode.Decompress)) //using (var iis = new ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream (partInputStream, new ICSharpCode.SharpZipLib.Zip.Compression.Inflater (true))) using (var fs = File.Open(outputPath, FileMode.Create)) { await iis.CopyToAsync(fs).ConfigureAwait(false); await fs.FlushAsync().ConfigureAwait(false); fs.Seek(0, SeekOrigin.Begin); fileHash = DownloadUtils.HashMd5(fs); LogDebugMessage("Hash of Downloaded File: {0}", fileHash); fs.Close(); } if (!string.IsNullOrEmpty(part.Md5) && !part.Md5.Equals(fileHash, StringComparison.InvariantCultureIgnoreCase)) { // TODO: HANDLE LogMessage("File MD5 Hash was invalid, deleting file: {0}", part.ToFile); File.Delete(outputPath); return(false); } return(true); }