public void Unarchive() { using (var inputStream = new FileStream(SourcePath, FileMode.Open, FileAccess.Read)) { using (var tempStream = new FileStream(SourcePath + ".tmp", FileMode.Create, FileAccess.ReadWrite)) { Compressor.GzipDecompress(inputStream, tempStream); tempStream.Seek(0, SeekOrigin.Begin); var header = new ArchiveEntityHeader(); header.ReadStream(tempStream); for (int i = 0; i < header.Length; i++) { var archiveFile = new ArchiveFile(); archiveFile.ReadHeader(tempStream); archiveFile.AbsolutePath = Path.Combine(TargetPath, archiveFile.RelativePath); ArchiveItems.Add(archiveFile); } ArchiveItems.ForEach(x => x.ReadContent(tempStream)); } File.Delete(SourcePath + ".tmp"); } }
public void Archive() { using (var tempStream = new FileStream(TargetPath + ".tmp", FileMode.Create, FileAccess.ReadWrite)) { var fileHeader = new ArchiveEntityHeader() { RelativePath = "", Length = ArchiveItems.Sum(x => x.GetFiles()), HashValue = "", }; fileHeader.WriteStream(tempStream); ArchiveItems.ForEach(x => x.WriteHeader(tempStream)); ArchiveItems.ForEach(x => x.WriteContent(tempStream)); tempStream.Seek(0, SeekOrigin.Begin); using (var outputStream = new FileStream(TargetPath, FileMode.Create, FileAccess.Write)) { Compressor.GzipCompress(tempStream, outputStream); } } File.Delete(TargetPath + ".tmp"); }
public override void ReadHeader(Stream inputStream) { var header = new ArchiveEntityHeader(); header.ReadStream(inputStream); RelativePath = header.RelativePath; Length = header.Length; HashValue = header.HashValue; }
public override void WriteHeader(Stream outputStream) { var header = new ArchiveEntityHeader() { RelativePath = RelativePath, Length = Length, HashValue = ToHexString(HashCalculator.Compute(HashCalculator.Algorithm.Sha1, AbsolutePath)), }; header.WriteStream(outputStream); }