public void BufferingWriter()
        {
            using var writer = new FileBufferingWriter(memoryThreshold: MemoryThreshold, asyncIO: false);
            foreach (var chunk in GetChunks())
            {
                writer.Write(chunk.Span);
            }
            writer.Flush();

            using var ms = new MemoryStream(content.Length);
            writer.CopyTo(ms);
        }
예제 #2
0
        public static void StressTest2(int threshold)
        {
            var dict = new Dictionary <string, string>
            {
                { "Key1", "Value1" },
                { "Key2", "Value2" }
            };
            var formatter = new BinaryFormatter();

            using var writer = new FileBufferingWriter(memoryThreshold: threshold, asyncIO: false);
            formatter.Serialize(writer, dict);
            using var source = new MemoryStream(1024);
            writer.CopyTo(source);
            source.Position = 0L;
            Equal(dict, formatter.Deserialize(source));
        }
        public static void DrainToSpan(int threshold)
        {
            using var writer = new FileBufferingWriter(memoryThreshold: threshold, asyncIO: false);
            var bytes = new byte[500];

            for (byte i = 0; i < byte.MaxValue; i++)
            {
                bytes[i] = i;
            }

            writer.Write(bytes, 0, byte.MaxValue);
            writer.Write(bytes.AsSpan(byte.MaxValue));
            Equal(bytes.Length, writer.Length);
            var buffer = new byte[100];

            Equal(buffer.Length, writer.CopyTo(buffer));
            Equal(bytes[0..100], buffer);
        public static void DrainToStream(int threshold)
        {
            using var writer = new FileBufferingWriter(memoryThreshold: threshold, asyncIO: false);
            var bytes = new byte[500];

            for (byte i = 0; i < byte.MaxValue; i++)
            {
                bytes[i] = i;
            }

            writer.Write(bytes, 0, byte.MaxValue);
            writer.Write(bytes.AsSpan(byte.MaxValue));
            Equal(bytes.Length, writer.Length);
            using var ms = new MemoryStream(500);
            writer.CopyTo(ms);
            Equal(bytes, ms.ToArray());
        }