Beispiel #1
0
        private static void Compress_SingleStream(string filename, int threads)
        {
            var timer = Stopwatch.StartNew();
            var fs    = File.Create(filename);
            var xz    = new XZCompressStream(fs, threads);

            using (var writer = new StreamWriter(xz, Encoding.UTF8))
            {
                for (int i = 0; i < CNT; i++)
                {
                    writer.WriteLine($"this is line {i} written in {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fffffff")}");
                    if (i % (CNT / 10) == 0)
                    {
                        Console.WriteLine($"writing {i} lines, {timer.Elapsed}");
                    }
                }
            }
            Console.WriteLine($"finished, {timer.Elapsed}");
        }
Beispiel #2
0
        private void TestDispose()
        {
            var c = new XZCompressStream("temp1.xz");

            c.Close();
            c.Close();

            c = new XZCompressStream("temp2.xz");
            c.Dispose();
            c.Dispose();

            var d = new XZDecompressStream("temp1.xz");

            d.Close();
            d.Close();

            d = new XZDecompressStream("temp2.xz");
            d.Dispose();
            d.Dispose();
        }
Beispiel #3
0
        private static void Compress_MultiStream(string filename, int threads)
        {
            var timer = Stopwatch.StartNew();

            // create a new xz file
            var fs = File.Create(filename);
            var xz = new XZCompressStream(fs, threads);

            using (var writer = new StreamWriter(xz, Encoding.UTF8))
            {
                for (int i = 0; i < CNT; i++)
                {
                    writer.WriteLine($"this is line {i} written in {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fffffff")}");
                    if (i % (CNT / 10) == 0)
                    {
                        Console.WriteLine($"writing {i} lines, {timer.Elapsed}");
                    }
                }
            }

            // open the same xz file and append new data
            fs = new FileStream(filename, FileMode.Append, FileAccess.Write, FileShare.None);
            xz = new XZCompressStream(fs, threads);
            using (var writer = new StreamWriter(xz, new UTF8Encoding(false, true))) // append data should go without BOM
            {
                for (int i = 0; i < CNT; i++)
                {
                    writer.WriteLine($"DATA APPENDED: this is line {i} written in {DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fffffff")}");
                    if (i % (CNT / 10) == 0)
                    {
                        Console.WriteLine($"writing {i} lines, {timer.Elapsed}");
                    }
                }
            }
            Console.WriteLine($"finished, {timer.Elapsed}");
        }