Exemple #1
0
        public static async Task CopyCharChunksToStream()
        {
            var bytes = new ChunkSequence <char>("Hello, world!".AsMemory(), 3);
            var sb    = new StringBuilder();

            using (var writer = new StringWriter(sb))
                await ChunkSequence.CopyToAsync(bytes, writer).ConfigureAwait(false);
            Equal("Hello, world!", sb.ToString());
        }
Exemple #2
0
        public static async Task CopyByteChunksToStream()
        {
            var bytes = new ChunkSequence <byte>(Encoding.UTF8.GetBytes("Hello, world!"), 3);

            using var content = new MemoryStream();
            await ChunkSequence.CopyToAsync(bytes, content).ConfigureAwait(false);

            content.Seek(0, SeekOrigin.Begin);
            using var reader = new StreamReader(content, Encoding.UTF8, false, 1024, true);
            Equal("Hello, world!", reader.ReadToEnd());
        }