public static void StressTest3()
        {
            var buffer = new byte[1024 * 1024 * 10];    // 10 MB

            new Random().NextBytes(buffer);
            using var writer = new FileBufferingWriter(asyncIO: false);
            writer.Write(buffer);
            False(writer.TryGetWrittenContent(out _));
            using var content = writer.GetWrittenContent();
            True(buffer.AsSpan().SequenceEqual(content.Memory.Span));
        }
Exemple #2
0
        public static void PermanentFile()
        {
            var    expected = RandomBytes(500);
            string fileName;

            using (var writer = new FileBufferingWriter(new FileBufferingWriter.Options {
                MemoryThreshold = 100, AsyncIO = false, FileName = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())
            }))
            {
                writer.Write(expected);
                False(writer.TryGetWrittenContent(out _, out fileName));
            }

            using var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            var actual = new byte[expected.Length];

            fs.ReadBlock(actual);
            Equal(expected, actual);
        }