public async void Case5() { var origF = SampleFinder.Get("sample_4.6mb"); var oldHash = origF.SHA1ForFile(); var outDir = TempDir.New(); var archives = await SevenZipper1.Compress(origF, outDir, 0.5); archives.MustHaveFiles(7); var list = await SevenZipper1.DecompressMultiPart(archives, outDir); foreach (var part in archives) { File.Exists(part).Should().BeFalse("Should delete parts after merge"); } list.Should().HaveCount(1); var newF = Path.Combine(outDir, list[0]); var newHash = newF.SHA1ForFile(); newHash.Should().Be(oldHash, "Hashes should match"); Directory.GetFiles(outDir).Length.Should().Be(2, "Should delete OneBigF"); Directory.Delete(outDir, true); }
public async Task <bool> UploadInParts(R1Package localPkg, double maxVolumeSizeMB) { var tmpCopy = CopyToTemp(localPkg.FullPathOrURL); _package = localPkg; _partPaths = await SevenZipper1.Compress(tmpCopy, null, maxVolumeSizeMB, ".data"); _pkgParts = new List <R1PackagePart>(); for (int i = 0; i < _partPaths.Count; i++) { var ok = await UploadPartByIndex(i); if (!ok) { return(false); } } return(true); }
public async void Case4() { var origF = SampleFinder.Get("sample_4.6mb"); var oldHash = origF.SHA1ForFile(); var outDir = TempDir.New(); var archives = await SevenZipper1.Compress(origF, outDir, 0.5); archives.MustHaveFiles(7); var list = await SevenZipper1.Decompress(archives[0], outDir); list.Should().HaveCount(1); var newF = Path.Combine(outDir, list[0]); var newHash = newF.SHA1ForFile(); newHash.Should().Be(oldHash, "Hashes should match"); Directory.Delete(outDir, true); }
internal async Task <bool> UploadNew (R1Executable localExe, double?maxVolumeSizeMB) { IsBusy = true; Status = "Compressing ..."; var tmpCopy = CopyToTemp(localExe.FullPathOrURL); var splitParts = new List <R1SplitPart>(); var partPaths = await SevenZipper1.Compress(tmpCopy, null, maxVolumeSizeMB, ".data"); for (int i = 0; i < partPaths.Count; i++) { Status = $"Uploading part {i + 1} of {partPaths.Count} ..."; var r1Part = FilePart.ToR1Part(partPaths[i], localExe, i + 1, partPaths.Count); var node = await Create(r1Part, () => GetSplitPartIDsByHash(r1Part.PartHash)); if (node == null) { return(false); } splitParts.Add(r1Part); } var ok = await ValidateDownload(splitParts, localExe.FileHash); if (!ok) { //todo: delete corrupted uploaded parts return(Alerter.Warn("Uploaded parts are invalid.", false)); } IsBusy = false; return(true); }