Esempio n. 1
0
        public static void Compress(
            string entryPath,
            Stream inStream,
            Stream outStream,
            ArchiveType archiveType,
            CompressionType compressionType,
            ProgressStreamReportDelegate progressCallback)
        {
            char[] dirSeparators = { '\\', '/' };

            if (progressCallback != null)
            {
                outStream = new ProgressStream(outStream);
                ((ProgressStream)outStream).BytesWritten += progressCallback;
            }

            using (var writer = WriterFactory.Open(outStream, archiveType, new WriterOptions(compressionType)))
            {
                writer.Write(entryPath, inStream);
            }

            if (progressCallback != null)
            {
                ((ProgressStream)outStream).BytesWritten -= progressCallback;
            }
        }
Esempio n. 2
0
        public static void Compress(
            string rootDir,
            IEnumerable <FileInfo> files,
            Stream outStream,
            ArchiveType archiveType,
            CompressionType compressionType,
            ProgressStreamReportDelegate progressCallback)
        {
            char[] dirSeparators = { '\\', '/' };

            if (progressCallback != null)
            {
                outStream = new ProgressStream(outStream);
                ((ProgressStream)outStream).BytesWritten += progressCallback;
            }

            int rootDirLen = rootDir.Length + (dirSeparators.Contains(rootDir.Last()) ? 0 : 1);

            using (var writer = WriterFactory.Open(outStream, archiveType, new WriterOptions(compressionType)))
            {
                foreach (FileInfo f in files)
                {
                    writer.Write(f.FullName.Substring(rootDirLen), f);
                }
            }

            if (progressCallback != null)
            {
                ((ProgressStream)outStream).BytesWritten -= progressCallback;
            }
        }