public async Task WriteBytesAsyncPartialWrite()
        {
            const int CopyLength = 200 * 1024;
            const int SourceLength = 300 * 1024;
            const int BufferCapacity = 400 * 1024;

            var bytes = new byte[SourceLength];
            var random = new Random(Guid.NewGuid().GetHashCode());
            random.NextBytes(bytes);

            IByteBuffer buffer = Unpooled.Buffer(BufferCapacity);
            int initialWriterIndex = buffer.WriterIndex;
            using (var stream = new PortionedMemoryStream(bytes, Enumerable.Repeat(1, int.MaxValue).Select(_ => random.Next(1, 10240))))
            {
                await buffer.WriteBytesAsync(stream, CopyLength);
            }
            Assert.Equal(CopyLength, buffer.WriterIndex - initialWriterIndex);
            Assert.True(ByteBufferUtil.Equals(Unpooled.WrappedBuffer(bytes.Slice(0, CopyLength)), buffer));
        }
        public async Task WriteBytesAsyncPartialWrite()
        {
            const int CopyLength     = 200 * 1024;
            const int SourceLength   = 300 * 1024;
            const int BufferCapacity = 400 * 1024;

            var bytes  = new byte[SourceLength];
            var random = new Random(Guid.NewGuid().GetHashCode());

            random.NextBytes(bytes);

            IByteBuffer buffer             = Unpooled.Buffer(BufferCapacity);
            int         initialWriterIndex = buffer.WriterIndex;

            using (var stream = new PortionedMemoryStream(bytes, Enumerable.Repeat(1, int.MaxValue).Select(_ => random.Next(1, 10240))))
            {
                await buffer.WriteBytesAsync(stream, CopyLength);
            }
            Assert.Equal(CopyLength, buffer.WriterIndex - initialWriterIndex);
            Assert.True(ByteBufferUtil.Equals(Unpooled.WrappedBuffer(bytes.Slice(0, CopyLength)), buffer));
        }