Beispiel #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;
            }
        }
Beispiel #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;
            }
        }
Beispiel #3
0
        public static long Process(
            Stream data,
            ArchiveType archiveType, CompressionType compType,
            EncryptionProtocol encProtocol, EncryptionAlgorithm encAlgorithm)
        {
            string   fileName  = Path.GetTempFileName();
            FileInfo fileInfo  = new FileInfo(fileName);
            long     compSizeB = 0;

            ProgressStreamReportDelegate progressCallback =
                (_, args) => compSizeB += args.BytesMoved;

            using (Stream outFileStream = fileInfo.OpenWrite())
            {
                Action <Stream> streamWriter =
                    (outStream) => CompressionHelper.Compress(
                        "data.bin",
                        data,
                        outStream,
                        archiveType,
                        compType,
                        progressCallback
                        );

                switch (encProtocol)
                {
                case EncryptionProtocol.None:
                    streamWriter(outFileStream);
                    break;

                case EncryptionProtocol.AES:
                    EncryptionHelper.EncryptStreamAES(streamWriter, outFileStream, encAlgorithm, Const.EncKey32);
                    break;

                case EncryptionProtocol.PBE:
                    EncryptionHelper.EncryptStreamPBE(streamWriter, outFileStream, encAlgorithm, Const.EncKey32);
                    break;

                case EncryptionProtocol.PGP:
                    using (Stream pgpPubKeyStream = new MemoryStream(Encoding.ASCII.GetBytes(Const.PGPPubKey)))
                        EncryptionHelper.EncryptStreamPGP(
                            streamWriter, outFileStream, encAlgorithm,
                            pgpPubKeyStream, Convert.ToInt64(Const.PGPPubKeyID, 16));
                    break;
                }
            }

            fileInfo.Delete();

            return(compSizeB);
        }
Beispiel #4
0
        public static IEnumerable <CEBenchResult> Run(
            Stream inStream, int iterationNb, ProgressStreamReportDelegate inReadCallback)
        {
            if (inReadCallback != null)
            {
                inStream = new ProgressStream(inStream);
                ((ProgressStream)inStream).BytesRead += inReadCallback;
            }

            var ret = Run(inStream, iterationNb);

            if (inReadCallback != null)
            {
                ((ProgressStream)inStream).BytesRead -= inReadCallback;
            }

            return(ret);
        }