Пример #1
0
        /// <inheritdoc />
        public byte ReadByte()
        {
            var result = Stream.ReadByte();

            if (result < 0)
            {
                EndOfStreamException.ThrowRead();
            }
            return((byte)result);
        }
Пример #2
0
        /// <inheritdoc />
        public void ReadBytes(byte[] buffer, int offset, int count)
        {
            var totalBytesRead = 0;

            while (totalBytesRead < count)
            {
                var bytesRead = Stream.Read(buffer, totalBytesRead, count - totalBytesRead);
                if (bytesRead == 0)
                {
                    EndOfStreamException.ThrowRead();
                }
                totalBytesRead += bytesRead;
            }
        }
Пример #3
0
        /// <inheritdoc />
        public async Task ReadBytesAsync(byte[] buffer, int offset, int count)
        {
            var totalBytesRead = 0;

            while (totalBytesRead < count)
            {
                var bytesRead = await Stream.ReadAsync(buffer, totalBytesRead, count - totalBytesRead).ConfigureAwait(false);

                if (bytesRead == 0)
                {
                    EndOfStreamException.ThrowRead();
                }
                totalBytesRead += bytesRead;
            }
        }