Example #1
0
            private async Task <ForkedStreamBuffer> GetNextPageAsync()
            {
                if (this.IsLastPage)
                {
                    return(null);
                }

                if (_nextPage == null)
                {
                    await _navGuard.WaitAsync();

                    try
                    {
                        if (_nextPage == null)
                        {
                            if (_pageAvailable != null)
                            {
                                await _pageAvailable.WaitAsync();
                            }

                            _nextPage = new ForkedStreamBuffer(this);
                        }
                    }
                    finally
                    {
                        _navGuard.Release();
                    }
                }

                return(_nextPage);
            }
Example #2
0
            public async override Task <int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken = default(CancellationToken))
            {
                if (_buffer == null)
                {
                    return(0);
                }

                var startPos = _position;

                _buffer = await _buffer.ReadAsync(this, buffer, offset, count);

                return(Convert.ToInt32(_position - startPos));
            }
Example #3
0
        public static Stream[] Fork(this Stream stream, int count, long bufferSize = 0)
        {
            Stream[] streams = new Stream[count];

            var buff = ForkedStreamBuffer.FromStream(stream, count, bufferSize);

            for (int i = 0; i < count; i++)
            {
                streams[i] = new ForkStream(buff);
            }

            return(streams);
        }
Example #4
0
            private ForkedStreamBuffer(Stream source, int feedCount, int pageSize, long basePos, SemaphoreSlim pagesAvailable)
            {
                _source = source;

                _pageData = new byte[pageSize];

                _basePos = basePos;

                _bytesRead = 0;

                _feedCount = feedCount;

                _readCount = 0;

                _initialized = false;

                _navGuard = new SemaphoreSlim(1, 1);

                _initGuard = new SemaphoreSlim(1, 1);

                _pageAvailable = pagesAvailable;

                _nextPage = null;
            }
Example #5
0
 public ForkStream(ForkedStreamBuffer buffer)
 {
     _buffer   = buffer;
     _position = 0;
 }
Example #6
0
 private ForkedStreamBuffer(ForkedStreamBuffer prevPage) :
     this(prevPage._source, prevPage._feedCount, prevPage.PageSize, prevPage._basePos + prevPage.PageSize, prevPage._pageAvailable)
 {
 }