From 1adcce6c62b3a5efcabaf890df9c01f957d4e7b1 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Sat, 9 Jan 2021 12:53:13 +0000 Subject: [PATCH] Expose Last Modified time on GZipStream --- .../Compressors/Deflate/GZipStream.cs | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/SharpCompress/Compressors/Deflate/GZipStream.cs b/src/SharpCompress/Compressors/Deflate/GZipStream.cs index 903cea2c..84fc1379 100644 --- a/src/SharpCompress/Compressors/Deflate/GZipStream.cs +++ b/src/SharpCompress/Compressors/Deflate/GZipStream.cs @@ -37,10 +37,9 @@ namespace SharpCompress.Compressors.Deflate { internal static readonly DateTime UNIX_EPOCH = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); - public DateTime? LastModified { get; set; } - private string? _comment; private string? _fileName; + private DateTime? _lastModified; internal ZlibBaseStream BaseStream; private bool _disposed; @@ -274,6 +273,7 @@ namespace SharpCompress.Compressors.Deflate _firstReadDone = true; FileName = BaseStream._GzipFileName; Comment = BaseStream._GzipComment; + LastModified = BaseStream._GzipMtime; } return n; } @@ -357,6 +357,20 @@ namespace SharpCompress.Compressors.Deflate _comment = value; } } + + + public DateTime? LastModified + { + get => _lastModified; + set + { + if (_disposed) + { + throw new ObjectDisposedException(nameof(GZipStream)); + } + _lastModified = value; + } + } public string? FileName { @@ -398,8 +412,8 @@ namespace SharpCompress.Compressors.Deflate byte[]? filenameBytes = (FileName is null) ? null : _encoding.GetBytes(FileName); - int cbLength = (commentBytes is null) ? 0 : commentBytes.Length + 1; - int fnLength = (filenameBytes is null) ? 0 : filenameBytes.Length + 1; + int cbLength = commentBytes?.Length + 1 ?? 0; + int fnLength = filenameBytes?.Length + 1 ?? 0; int bufferLength = 10 + cbLength + fnLength; var header = new byte[bufferLength]; @@ -425,7 +439,7 @@ namespace SharpCompress.Compressors.Deflate header[i++] = flag; // mtime - if (!LastModified.HasValue) + if (LastModified is null) { LastModified = DateTime.Now; }