Exemple #1
0
        private async Task <byte[]> LoadDataAsync(int blockIndex)
        {
            ThrowIfDisposed();

            if (m_blocks !.Count <= blockIndex)
            {
                m_blocks.AddRange(new byte[blockIndex - m_blocks.Count + 1][]);
            }

            var blockData = m_blocks[blockIndex];

            if (blockData is null)
            {
                WrappedStream.Position = blockIndex * c_blockSize;
                blockData = new byte[c_blockSize];
                var bytesRead = await WrappedStream.ReadBlockAsync(blockData, 0, blockData.Length).ConfigureAwait(false);

                if (bytesRead != c_blockSize)
                {
                    Array.Resize(ref blockData, bytesRead);
                }
                m_blocks[blockIndex] = blockData;
            }

            return(blockData);
        }