예제 #1
0
        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");
        }
예제 #2
0
        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);
        }