示例#1
0
        public static void Decode(
            TextReader input,
            Stream output,
            Func <ReadOnlyMemory <Char>, Memory <Byte> > decodeBufferFunc,
            Int32 bufferSize = BufferUtils.DefaultBuffer)
        {
            Char[] buffer = new Char[bufferSize];
            while (true)
            {
                Int32 bytesRead = input.Read(buffer, 0, bufferSize);
                if (bytesRead < 1)
                {
                    break;
                }

                Memory <Byte> result = decodeBufferFunc(buffer.AsMemory(0, bytesRead));
                output.Write(result.ToArray(), 0, result.Length);
            }
        }
示例#2
0
        public static async Task DecodeAsync(
            TextReader input,
            Stream output,
            Func <ReadOnlyMemory <Char>, Memory <Byte> > decodeBufferFunc,
            Int32 bufferSize = BufferUtils.DefaultBuffer)
        {
            Char[] buffer = new Char[bufferSize];
            while (true)
            {
                Int32 bytesRead = await input.ReadAsync(buffer, 0, bufferSize).ConfigureAwait(false);

                if (bytesRead < 1)
                {
                    break;
                }

                Memory <Byte> result = decodeBufferFunc(buffer.AsMemory(0, bytesRead));
                await output.WriteAsync(result.ToArray(), 0, result.Length).ConfigureAwait(false);
            }
        }