Ejemplo n.º 1
0
        private async Task <Stream> GetStreamAsync()
        {
            var    content       = _httpResponseMessage.Content;
            Stream contentStream = null;

            _contentLength = -1;
            if (content != null)
            {
                contentStream = await content.ReadAsStreamAsync();

                _contentLength = content.Headers.ContentLength.HasValue ? content.Headers.ContentLength.Value : -1;
                if (_contentLength <= 0)
                {
                    var preReadBuffer = new byte[1];
                    if (await contentStream.ReadAsync(preReadBuffer, 0, 1) == 0)
                    {
                        preReadBuffer = null;
                        contentStream.Dispose();
                        contentStream = null;
                    }
                    else
                    {
                        contentStream = new PreReadStream(contentStream, preReadBuffer);
                    }
                }
            }

            return(contentStream);
        }
Ejemplo n.º 2
0
        private async Task<Stream> GetStreamAsync()
        {
            var content = _httpResponseMessage.Content;
            Stream contentStream = null;
            _contentLength = -1;
            if (content != null)
            {
                contentStream = await content.ReadAsStreamAsync();
                _contentLength = content.Headers.ContentLength.HasValue ? content.Headers.ContentLength.Value : - 1;
                if (_contentLength <= 0)
                {
                    var preReadBuffer = new byte[1];
                    if (await contentStream.ReadAsync(preReadBuffer, 0, 1) == 0)
                    {
                        preReadBuffer = null;
                        contentStream.Dispose();
                        contentStream = null;
                    }
                    else
                    {
                        contentStream = new PreReadStream(contentStream, preReadBuffer);
                    }
                }
            }

            return contentStream;
        }