Anul 3 Semestrul 2

This commit is contained in:
2025-07-03 20:56:38 +03:00
parent 184f3bd92e
commit 3b7fb85767
269 changed files with 20955 additions and 0 deletions
@@ -0,0 +1,43 @@
using System;
using System.IO.Compression;
using FileCompression.Interfaces;
using FileCompression.Services.Strategies;
namespace FileCompression.Services.Composites;
public class TarCompressor : ICompressor
{
private readonly string sourcePath;
private readonly string destinationPath;
private readonly StrategyContext strategyContext;
private readonly string basePath;
private readonly string tarPath;
private ICompressor compressor;
public TarCompressor(string sourcePath, string destinationPath, string basePath, StrategyContext strategyContext)
{
this.sourcePath = sourcePath;
this.destinationPath = destinationPath;
this.strategyContext = strategyContext;
this.basePath = basePath;
this.tarPath = destinationPath + ".tar";
compressor = File.Exists(sourcePath) ? new FileCompressor(sourcePath, tarPath, basePath, strategyContext) : new FolderCompressor(sourcePath, tarPath, basePath, strategyContext);
}
public void Compress()
{
compressor.Compress();
GZipCompress();
}
private void GZipCompress()
{
using (var fileStream = new FileStream(tarPath, FileMode.Open))
using (var compressedFileStream = File.Create(destinationPath))
using (var compressionStream = new GZipStream(compressedFileStream, CompressionLevel.Optimal))
{
fileStream.CopyTo(compressionStream);
}
File.Delete(tarPath);
}
}