Example #1
0
        /// <summary>
        /// Read raw bytes while data is on the stream, waiting up to the timeout value for more data.
        /// </summary>
        public byte[] ReadBytesToTimeout(Action <long> receiveProgress = null)
        {
            var ms = new MemoryStream((int)_expectedLength);

            StreamTools.CopyBytesToTimeout(_source, ms, receiveProgress);
            _readSoFar += ms.Length;
            return(ms.ToArray());
        }
        /// <summary>
        /// Read raw bytes up to the declared response length.
        /// If response is chunked, this will read until an empty chunk is received.
        /// </summary>
        public byte[] ReadBytesToLength(Action <long> receiveProgress = null)
        {
            var ms = new MemoryStream((int)ExpectedLength);

            lock (_lock)
            {
                ExpectedLength = StreamTools.CopyBytesToLength(_source, ms, ExpectedLength, Timeout, receiveProgress);
            }
            _readSoFar += ms.Length;
            return(ms.ToArray());
        }