From bee7f43880f40b339291c0127aa2743e798dca8e Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 26 Apr 2018 09:46:01 +0100 Subject: [PATCH] Expose stream length. Clean up entry stream --- .gitignore | 1 + src/SharpCompress/Common/EntryStream.cs | 33 +++++++++++-------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 2e0b14fa..ca133c68 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ tests/TestArchives/Scratch tools .vscode .idea/ +.DS_Store diff --git a/src/SharpCompress/Common/EntryStream.cs b/src/SharpCompress/Common/EntryStream.cs index 0120b782..4697ff8c 100644 --- a/src/SharpCompress/Common/EntryStream.cs +++ b/src/SharpCompress/Common/EntryStream.cs @@ -6,15 +6,15 @@ namespace SharpCompress.Common { public class EntryStream : Stream { - public IReader Reader { get; } - private readonly Stream stream; - private bool completed; - private bool isDisposed; + private readonly IReader _reader; + private readonly Stream _stream; + private bool _completed; + private bool _isDisposed; internal EntryStream(IReader reader, Stream stream) { - Reader = reader; - this.stream = stream; + _reader = reader; + _stream = stream; } /// @@ -22,26 +22,23 @@ namespace SharpCompress.Common /// public void SkipEntry() { - var buffer = new byte[4096]; - while (Read(buffer, 0, buffer.Length) > 0) - { - } - completed = true; + this.Skip(); + _completed = true; } protected override void Dispose(bool disposing) { - if (!(completed || Reader.Cancelled)) + if (!(_completed || _reader.Cancelled)) { SkipEntry(); } - if (isDisposed) + if (_isDisposed) { return; } - isDisposed = true; + _isDisposed = true; base.Dispose(disposing); - stream.Dispose(); + _stream.Dispose(); } public override bool CanRead => true; @@ -55,16 +52,16 @@ namespace SharpCompress.Common throw new NotSupportedException(); } - public override long Length => throw new NotSupportedException(); + public override long Length => _stream.Length; public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { - int read = stream.Read(buffer, offset, count); + int read = _stream.Read(buffer, offset, count); if (read <= 0) { - completed = true; + _completed = true; } return read; }