Skip to content

Commit

Permalink
Merge branch 'master' into fix-xzblock-padding
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock authored Dec 20, 2024
2 parents f51bdd5 + 7f79c49 commit 10cc270
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 44 deletions.
1 change: 1 addition & 0 deletions src/SharpCompress/Archives/Rar/FileInfoRarArchiveVolume.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using SharpCompress.Common.Rar;
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/BufferPool.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Buffers;

namespace SharpCompress;
namespace SharpCompress.Helpers;

internal static class BufferPool
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ public UnixTimeExtraField(ExtraDataType type, ushort length, byte[] dataBytes)
return Tuple.Create<DateTime?, DateTime?, DateTime?>(null, null, null);
}

var flags = DataBytes[0];
var isModifiedTimeSpecified = (flags & 0x01) == 1;
var isLastAccessTimeSpecified = (flags & 0x02) == 1;
var isCreationTimeSpecified = (flags & 0x04) == 1;
var flags = (RecordedTimeFlag)DataBytes[0];
var isModifiedTimeSpecified = flags.HasFlag(RecordedTimeFlag.LastModified);
var isLastAccessTimeSpecified = flags.HasFlag(RecordedTimeFlag.LastAccessed);
var isCreationTimeSpecified = flags.HasFlag(RecordedTimeFlag.Created);
var currentIndex = 1;
DateTime? modifiedTime = null;
DateTime? lastAccessTime = null;
Expand All @@ -189,7 +189,7 @@ public UnixTimeExtraField(ExtraDataType type, ushort length, byte[] dataBytes)
{
if (currentIndex + 4 > DataBytes.Length)
{
throw new ArchiveException("Invalid UnicodeExtraTime field");
return Tuple.Create<DateTime?, DateTime?, DateTime?>(null, null, null);
}

var lastAccessEpochTime = BinaryPrimitives.ReadInt32LittleEndian(
Expand All @@ -206,7 +206,7 @@ public UnixTimeExtraField(ExtraDataType type, ushort length, byte[] dataBytes)
{
if (currentIndex + 4 > DataBytes.Length)
{
throw new ArchiveException("Invalid UnicodeExtraTime field");
return Tuple.Create<DateTime?, DateTime?, DateTime?>(null, null, null);
}

var creationTimeEpochTime = BinaryPrimitives.ReadInt32LittleEndian(
Expand All @@ -222,6 +222,15 @@ public UnixTimeExtraField(ExtraDataType type, ushort length, byte[] dataBytes)
return Tuple.Create(modifiedTime, lastAccessTime, creationTime);
}
}

[Flags]
private enum RecordedTimeFlag
{
None = 0,
LastModified = 1,
LastAccessed = 2,
Created = 4
}
}

internal static class LocalEntryHeaderExtraFactory
Expand Down
24 changes: 21 additions & 3 deletions src/SharpCompress/Common/Zip/ZipEntry.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SharpCompress.Common.Zip.Headers;

namespace SharpCompress.Common.Zip;
Expand All @@ -15,10 +16,19 @@ internal ZipEntry(ZipFilePart? filePart)
return;
}
_filePart = filePart;

LastModifiedTime = Utility.DosDateToDateTime(
filePart.Header.LastModifiedDate,
filePart.Header.LastModifiedTime
);

var times =
filePart.Header.Extra.FirstOrDefault(header =>
header.GetType() == typeof(UnixTimeExtraField)
) as UnixTimeExtraField;

LastAccessedTime = times?.UnicodeTimes.Item2;
CreatedTime = times?.UnicodeTimes.Item3;
}

public override CompressionType CompressionType =>
Expand Down Expand Up @@ -51,9 +61,17 @@ internal ZipEntry(ZipFilePart? filePart)

public override DateTime? LastModifiedTime { get; }

public override DateTime? CreatedTime => null;

public override DateTime? LastAccessedTime => null;
/// <inheritdoc/>
/// <remarks>
/// The returned time is UTC, not local.
/// </remarks>
public override DateTime? CreatedTime { get; }

/// <inheritdoc/>
/// <remarks>
/// The returned time is UTC, not local.
/// </remarks>
public override DateTime? LastAccessedTime { get; }

public override DateTime? ArchivedTime => null;

Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/LazyReadOnlyCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections;
using System.Collections.Generic;

namespace SharpCompress;
namespace SharpCompress.Helpers;

internal sealed class LazyReadOnlyCollection<T> : ICollection<T>
{
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/NotNullExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Linq;
using System.Runtime.CompilerServices;

namespace SharpCompress;
namespace SharpCompress.Helpers;

public static class NotNullExtensions
{
Expand Down
30 changes: 0 additions & 30 deletions src/SharpCompress/ReadOnlyCollection.cs

This file was deleted.

6 changes: 4 additions & 2 deletions src/SharpCompress/Utility.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
global using SharpCompress.Helpers;
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Text;
using SharpCompress.Readers;

namespace SharpCompress;
namespace SharpCompress.Helpers;

[CLSCompliant(false)]
public static class Utility
{
public static ReadOnlyCollection<T> ToReadOnly<T>(this ICollection<T> items) => new(items);
public static ReadOnlyCollection<T> ToReadOnly<T>(this IList<T> items) => new(items);

/// <summary>
/// Performs an unsigned bitwise right shift with the specified number
Expand Down
1 change: 1 addition & 0 deletions tests/SharpCompress.Test/TestBase.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
global using SharpCompress.Helpers;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down

0 comments on commit 10cc270

Please sign in to comment.