예제 #1
0
        public static Task <List <string> > Decompress(string archivePath, string targetDir)
        {
            if (FileChunker1.IsPartOfMany(archivePath))
            {
                archivePath = FileChunker1.Merge(archivePath);
            }

            return(ExtractSoloArchive(archivePath, targetDir));
        }
예제 #2
0
        public static Task <List <string> > DecompressMultiPart(IEnumerable <string> orderedParts, string targetDir)
        {
            var oneBigF = Path.Combine(targetDir, $"OneBigFile_{DateTime.Now.Ticks}.merged");

            FileChunker1.WriteOneBigFile(oneBigF, orderedParts);

            foreach (var part in orderedParts)
            {
                SilentDelete(part);
            }

            var list = ExtractSoloArchive(oneBigF, targetDir);

            SilentDelete(oneBigF);

            return(list);
        }
예제 #3
0
        public static Task <List <string> > Compress(string filePath,
                                                     string targetFDir      = null,
                                                     double?maxVolumeSizeMB = null,
                                                     string extension       = ".7z")
        {
            var tcs  = new TaskCompletionSource <List <string> >();
            var zpr  = GetUltra7z2Compressor();
            var outF = "";

            if (targetFDir.IsBlank())
            {
                targetFDir = Path.GetDirectoryName(filePath);
                outF       = filePath + extension;
            }
            else
            {
                Directory.CreateDirectory(targetFDir);
                outF = Path.Combine(targetFDir, Path.GetFileName(filePath) + extension);
            }

            zpr.CompressionFinished += (s, e) =>
            {
                if (maxVolumeSizeMB.HasValue)
                {
                    var parts = FileChunker1.Split(outF, targetFDir, maxVolumeSizeMB.Value);
                    tcs.SetResult(parts);
                }
                else
                {
                    tcs.SetResult(new List <string> {
                        outF
                    });
                }
            };

            zpr.BeginCompressFiles(outF, filePath);

            return(tcs.Task);
        }