@@ -23,7 +23,9 @@ internal class TarGzArchive : IArchive
23
23
private readonly CompressionLevel _compressionLevel ;
24
24
25
25
// Use a tar archive because .tar.gz file is a compressed tar file
26
- private TarArchive _tarArchive ;
26
+ private TarArchive ? _tarArchive ;
27
+
28
+ private string ? _tarFilePath ;
27
29
28
30
ArchiveMode IArchive . Mode => _mode ;
29
31
@@ -39,17 +41,22 @@ public TarGzArchive(string path, ArchiveMode mode, FileStream fileStream, Compre
39
41
40
42
void IArchive . AddFileSystemEntry ( ArchiveAddition entry )
41
43
{
44
+ if ( _mode == ArchiveMode . Extract ) {
45
+ throw new ArgumentException ( "Adding entries to the archive is not supported in extract mode" ) ;
46
+ }
47
+
42
48
if ( _mode == ArchiveMode . Create ) {
43
-
49
+ if ( _tarArchive is null ) {
50
+ _tarArchive = new TarArchive ( _path , ArchiveMode . Create , _fileStream ) ;
51
+ }
52
+ ( _tarArchive as IArchive ) . AddFileSystemEntry ( entry ) ;
44
53
}
45
54
}
46
55
47
56
IEntry ? IArchive . GetNextEntry ( )
48
57
{
49
- // Gzip has no concept of entries
50
- if ( ! _didCallGetNextEntry ) {
51
- _didCallGetNextEntry = true ;
52
- return new TarGzArchiveEntry ( this ) ;
58
+ if ( _mode == ArchiveMode . Create || _mode == ArchiveMode . Update ) {
59
+ throw new ArgumentException ( "Getting the entries in an archive is not supported in Create or Update mode" ) ;
53
60
}
54
61
return null ;
55
62
}
@@ -62,6 +69,7 @@ protected virtual void Dispose(bool disposing)
62
69
{
63
70
// TODO: dispose managed state (managed objects)
64
71
_fileStream . Dispose ( ) ;
72
+ CompressArchive ( ) ;
65
73
}
66
74
67
75
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
@@ -82,6 +90,14 @@ bool IArchive.HasTopLevelDirectory()
82
90
throw new NotSupportedException ( ) ;
83
91
}
84
92
93
+ // Performs gzip compression on _path
94
+ private void CompressArchive ( ) {
95
+ //using var destinationFileStream = new FileStream(destinationPath, FileMode.CreateNew, FileAccess.Write, FileShare.None);
96
+ _fileStream . Position = 0 ;
97
+ using var gzipDecompressor = new GZipStream ( _fileStream , _compressionLevel , true ) ;
98
+ _fileStream . CopyTo ( gzipDecompressor ) ;
99
+ }
100
+
85
101
internal class TarGzArchiveEntry : IEntry {
86
102
87
103
private TarGzArchive _gzipArchive ;
0 commit comments