Beispiel #1
0
        public static void Compress(Stream source, Stream destination, Action <long> reportProgress = null)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            var compressor = new ChunkedCompressor(source, reportProgress);

            compressor.Compress(destination);
        }
Beispiel #2
0
        private static (long outputSize, bool compressed) OptimizeStorage(Stream source, Stream destination, Action <long> reportProgress)
        {
            using var tempStream = CreateTempStream(source.Length);

            ChunkedCompressor.Compress(source, tempStream, reportProgress);

            if ((double)tempStream.Length / source.Length > 0.8)
            {
                destination.WriteByte(0);
                source.Position = 0;
                source.CopyTo(destination);
                return(source.Length, false);
            }
            else
            {
                destination.WriteByte(1);
                tempStream.Position = 0;
                tempStream.CopyTo(destination);
                return(tempStream.Length, true);
            }
        }