Example #1
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (storage == null)
            {
                throw new ObjectDisposedException("AutoPositionReadOnlyStream");
            }

            var read = storage.Read(position, buffer, offset, count);

            position += read;
            return(read);
        }
Example #2
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            ThrowIfDisposed();

            if (null == buffer)
            {
                throw new ArgumentNullException("buffer");
            }

            if (offset > buffer.Length || offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", Strings.OffsetOutOfRange);
            }

            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", Strings.CountOutOfRange);
            }

            if (count + offset > buffer.Length)
            {
                throw new ArgumentOutOfRangeException("count", Strings.CountTooLarge);
            }

            var readTotal = 0;
            int read;

            if ((end == long.MaxValue || position < end - start) && count != 0)
            {
                if (end != long.MaxValue && count > end - start - position)
                {
                    count = (int)(end - start - position);
                }

                do
                {
                    read = baseStorage.Read(start + position, buffer, offset, count);

                    count  -= read;
                    offset += read;

                    position += read;

                    readTotal += read;
                }while (count != 0 && read != 0);
            }

            return(readTotal);
        }