< Summary

Class:Azure.Storage.ProgressIncrementingStream
Assembly:Azure.Storage.Files.Shares
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Common\src\Shared\ProgressIncrementingStream.cs
Covered lines:19
Uncovered lines:35
Coverable lines:54
Total lines:147
Line coverage:35.1% (19 of 54)
Covered branches:2
Total branches:6
Branch coverage:33.3% (2 of 6)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
.ctor(...)-100%50%
get_CanRead()-100%100%
get_CanSeek()-100%100%
get_CanTimeout()-0%100%
get_CanWrite()-0%100%
Dispose(...)-0%100%
FlushAsync()-0%100%
Flush()-0%100%
get_Length()-100%100%
get_Position()-100%100%
set_Position(...)-0%100%
Read(...)-100%100%
ReadAsync()-100%100%
ReadByte()-0%0%
get_ReadTimeout()-0%100%
set_ReadTimeout(...)-0%100%
Seek(...)-100%100%
SetLength(...)-0%100%
Write(...)-0%100%
WriteAsync()-0%100%
WriteByte(...)-0%100%
get_WriteTimeout()-0%100%
set_WriteTimeout(...)-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Common\src\Shared\ProgressIncrementingStream.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.IO;
 6using System.Threading;
 7using System.Threading.Tasks;
 8
 9namespace Azure.Storage
 10{
 11    /// <summary>
 12    /// Wraps a stream, and reports position updates to a progress incrementer
 13    /// </summary>
 14    internal class ProgressIncrementingStream : Stream
 15    {
 16        private readonly Stream _innerStream;
 17        private readonly AggregatingProgressIncrementer _incrementer;
 18
 219        public ProgressIncrementingStream(Stream stream, AggregatingProgressIncrementer incrementer)
 20        {
 221            _innerStream = stream ?? throw Errors.ArgumentNull(nameof(stream));
 222            _incrementer = incrementer ?? throw Errors.ArgumentNull(nameof(incrementer));
 223        }
 24
 225        public override bool CanRead => _innerStream.CanRead;
 26
 827        public override bool CanSeek => _innerStream.CanSeek;
 28
 029        public override bool CanTimeout => _innerStream.CanTimeout;
 30
 031        public override bool CanWrite => _innerStream.CanWrite;
 32
 033        protected override void Dispose(bool disposing) => _innerStream.Dispose();
 34
 35        public override async Task FlushAsync(CancellationToken cancellationToken)
 36        {
 037            var oldPosition = _innerStream.Position;
 38
 039            await _innerStream.FlushAsync(cancellationToken).ConfigureAwait(false);
 40
 041            var newPosition = _innerStream.Position;
 42
 043            _incrementer.Report(newPosition - oldPosition);
 044        }
 45
 46        public override void Flush()
 47        {
 048            var oldPosition = _innerStream.Position;
 49
 050            _innerStream.Flush();
 51
 052            var newPosition = _innerStream.Position;
 53
 054            _incrementer.Report(newPosition - oldPosition);
 055        }
 56
 857        public override long Length => _innerStream.Length;
 58
 59        public override long Position
 60        {
 261            get => _innerStream.Position;
 62
 63            set
 64            {
 065                var delta = value - _innerStream.Position;
 66
 067                _innerStream.Position = value;
 68
 069                _incrementer.Report(delta);
 070            }
 71        }
 72
 73        public override int Read(byte[] buffer, int offset, int count)
 74        {
 3075            var n = _innerStream.Read(buffer, offset, count);
 2976            _incrementer.Report(n);
 2977            return n;
 78        }
 79
 80        public override async Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationTo
 81        {
 1282            var n = await _innerStream.ReadAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false);
 1183            _incrementer.Report(n);
 1184            return n;
 1185        }
 86
 87        public override int ReadByte()
 88        {
 089            var b = _innerStream.ReadByte();
 90
 091            if (b != -1) // -1 = end of stream sentinel
 92            {
 093                _incrementer.Report(1);
 94            }
 95
 096            return b;
 97        }
 98
 99        public override int ReadTimeout
 100        {
 0101            get => _innerStream.ReadTimeout;
 102
 0103            set => _innerStream.ReadTimeout = value;
 104        }
 105
 106        public override long Seek(long offset, SeekOrigin origin)
 107        {
 6108            var oldPosition = _innerStream.Position;
 109
 6110            var newPosition = _innerStream.Seek(offset, origin);
 111
 6112            _incrementer.Report(newPosition - oldPosition);
 113
 6114            return newPosition;
 115        }
 116
 0117        public override void SetLength(long value) => _innerStream.SetLength(value);
 118
 119        public override void Write(byte[] buffer, int offset, int count)
 120        {
 0121            _innerStream.Write(buffer, offset, count);
 122
 0123            _incrementer.Report(count);
 0124        }
 125
 126        public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
 127        {
 0128            await _innerStream.WriteAsync(buffer, offset, count, cancellationToken).ConfigureAwait(false);
 129
 0130            _incrementer.Report(count);
 0131        }
 132
 133        public override void WriteByte(byte value)
 134        {
 0135            _innerStream.WriteByte(value);
 136
 0137            _incrementer.Report(1);
 0138        }
 139
 140        public override int WriteTimeout
 141        {
 0142            get => _innerStream.WriteTimeout;
 143
 0144            set => _innerStream.WriteTimeout = value;
 145        }
 146    }
 147}