Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ IEnumerable<string> GetFiles(string d)
}
else
{
// Not tagged - create prerelease version based on next minor version
// Not tagged - create prerelease version
var allTags = (await GetGitOutput("tag", "--list"))
.Split('\n', StringSplitOptions.RemoveEmptyEntries)
.Where(tag => Regex.IsMatch(tag.Trim(), @"^\d+\.\d+\.\d+$"))
Expand All @@ -240,8 +240,22 @@ IEnumerable<string> GetFiles(string d)
var lastTag = allTags.OrderBy(tag => Version.Parse(tag)).LastOrDefault() ?? "0.0.0";
var lastVersion = Version.Parse(lastTag);

// Increment minor version for next release
var nextVersion = new Version(lastVersion.Major, lastVersion.Minor + 1, 0);
// Determine version increment based on branch
var currentBranch = await GetCurrentBranch();
Version nextVersion;

if (currentBranch == "release")
{
// Release branch: increment patch version
nextVersion = new Version(lastVersion.Major, lastVersion.Minor, lastVersion.Build + 1);
Console.WriteLine($"Building prerelease for release branch (patch increment)");
}
else
{
// Master or other branches: increment minor version
nextVersion = new Version(lastVersion.Major, lastVersion.Minor + 1, 0);
Console.WriteLine($"Building prerelease for {currentBranch} branch (minor increment)");
}

// Use commit count since the last version tag if available; otherwise, fall back to total count
var revListArgs = allTags.Any() ? $"--count {lastTag}..HEAD" : "--count HEAD";
Expand All @@ -253,6 +267,28 @@ IEnumerable<string> GetFiles(string d)
}
}

static async Task<string> GetCurrentBranch()
{
// In GitHub Actions, GITHUB_REF_NAME contains the branch name
var githubRefName = Environment.GetEnvironmentVariable("GITHUB_REF_NAME");
if (!string.IsNullOrEmpty(githubRefName))
{
return githubRefName;
}

// Fallback to git command for local builds
try
{
var (output, _) = await ReadAsync("git", "branch --show-current");
return output.Trim();
}
catch (Exception ex)
{
Console.WriteLine($"Warning: Could not determine current branch: {ex.Message}");
return "unknown";
}
}

static async Task<string> GetGitOutput(string command, string args)
{
try
Expand Down
14 changes: 3 additions & 11 deletions src/SharpCompress/Archives/ArchiveFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,14 @@ private static T FindFactory<T>(Stream stream)
);
}

public static bool IsArchive(
string filePath,
out ArchiveType? type,
int bufferSize = ReaderOptions.DefaultBufferSize
)
public static bool IsArchive(string filePath, out ArchiveType? type)
{
filePath.NotNullOrEmpty(nameof(filePath));
using Stream s = File.OpenRead(filePath);
return IsArchive(s, out type, bufferSize);
return IsArchive(s, out type);
}

public static bool IsArchive(
Stream stream,
out ArchiveType? type,
int bufferSize = ReaderOptions.DefaultBufferSize
)
public static bool IsArchive(Stream stream, out ArchiveType? type)
{
type = null;
stream.NotNull(nameof(stream));
Expand Down
7 changes: 2 additions & 5 deletions src/SharpCompress/Archives/AutoArchiveFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ class AutoArchiveFactory : IArchiveFactory

public IEnumerable<string> GetSupportedExtensions() => throw new NotSupportedException();

public bool IsArchive(
Stream stream,
string? password = null,
int bufferSize = ReaderOptions.DefaultBufferSize
) => throw new NotSupportedException();
public bool IsArchive(Stream stream, string? password = null) =>
throw new NotSupportedException();

public FileInfo? GetFilePart(int index, FileInfo part1) => throw new NotSupportedException();

Expand Down
6 changes: 2 additions & 4 deletions src/SharpCompress/Archives/IArchiveEntryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace SharpCompress.Archives;

public static class IArchiveEntryExtensions
{
private const int BufferSize = 81920;

/// <param name="archiveEntry">The archive entry to extract.</param>
extension(IArchiveEntry archiveEntry)
{
Expand All @@ -28,7 +26,7 @@ public void WriteTo(Stream streamToWriteTo, IProgress<ProgressReport>? progress

using var entryStream = archiveEntry.OpenEntryStream();
var sourceStream = WrapWithProgress(entryStream, archiveEntry, progress);
sourceStream.CopyTo(streamToWriteTo, BufferSize);
sourceStream.CopyTo(streamToWriteTo, Constants.BufferSize);
}

/// <summary>
Expand All @@ -51,7 +49,7 @@ public async Task WriteToAsync(
using var entryStream = await archiveEntry.OpenEntryStreamAsync(cancellationToken);
var sourceStream = WrapWithProgress(entryStream, archiveEntry, progress);
await sourceStream
.CopyToAsync(streamToWriteTo, BufferSize, cancellationToken)
.CopyToAsync(streamToWriteTo, Constants.BufferSize, cancellationToken)
.ConfigureAwait(false);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/SharpCompress/Archives/Tar/TarArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ var header in TarHeaderFactory.ReadHeader(
using (var entryStream = entry.OpenEntryStream())
{
using var memoryStream = new MemoryStream();
entryStream.CopyTo(memoryStream);
entryStream.CopyTo(memoryStream, Constants.BufferSize);
memoryStream.Position = 0;
var bytes = memoryStream.ToArray();

Expand Down
35 changes: 10 additions & 25 deletions src/SharpCompress/Archives/Zip/ZipArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,38 +124,27 @@ public static ZipArchive Open(Stream stream, ReaderOptions? readerOptions = null
);
}

public static bool IsZipFile(
string filePath,
string? password = null,
int bufferSize = ReaderOptions.DefaultBufferSize
) => IsZipFile(new FileInfo(filePath), password, bufferSize);

public static bool IsZipFile(
FileInfo fileInfo,
string? password = null,
int bufferSize = ReaderOptions.DefaultBufferSize
)
public static bool IsZipFile(string filePath, string? password = null) =>
IsZipFile(new FileInfo(filePath), password);

public static bool IsZipFile(FileInfo fileInfo, string? password = null)
{
if (!fileInfo.Exists)
{
return false;
}
using Stream stream = fileInfo.OpenRead();
return IsZipFile(stream, password, bufferSize);
return IsZipFile(stream, password);
}

public static bool IsZipFile(
Stream stream,
string? password = null,
int bufferSize = ReaderOptions.DefaultBufferSize
)
public static bool IsZipFile(Stream stream, string? password = null)
{
var headerFactory = new StreamingZipHeaderFactory(password, new ArchiveEncoding(), null);
try
{
if (stream is not SharpCompressStream)
{
stream = new SharpCompressStream(stream, bufferSize: bufferSize);
stream = new SharpCompressStream(stream, bufferSize: Constants.BufferSize);
}

var header = headerFactory
Expand All @@ -177,18 +166,14 @@ public static bool IsZipFile(
}
}

public static bool IsZipMulti(
Stream stream,
string? password = null,
int bufferSize = ReaderOptions.DefaultBufferSize
)
public static bool IsZipMulti(Stream stream, string? password = null)
{
var headerFactory = new StreamingZipHeaderFactory(password, new ArchiveEncoding(), null);
try
{
if (stream is not SharpCompressStream)
{
stream = new SharpCompressStream(stream, bufferSize: bufferSize);
stream = new SharpCompressStream(stream, bufferSize: Constants.BufferSize);
}

var header = headerFactory
Expand Down Expand Up @@ -229,7 +214,7 @@ protected override IEnumerable<ZipVolume> LoadVolumes(SourceStream stream)
if (streams.Count() > 1) //test part 2 - true = multipart not split
{
streams[1].Position += 4; //skip the POST_DATA_DESCRIPTOR to prevent an exception
var isZip = IsZipFile(streams[1], ReaderOptions.Password, ReaderOptions.BufferSize);
var isZip = IsZipFile(streams[1], ReaderOptions.Password);
streams[1].Position -= 4;
if (isZip)
{
Expand Down
10 changes: 10 additions & 0 deletions src/SharpCompress/Common/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SharpCompress.Common;

public static class Constants
{
/// <summary>
/// The default buffer size for stream operations, matching .NET's Stream.CopyTo default of 81920 bytes.
/// This can be modified globally at runtime.
/// </summary>
public static int BufferSize { get; set; } = 81920;
}
6 changes: 1 addition & 5 deletions src/SharpCompress/Factories/AceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ public override IEnumerable<string> GetSupportedExtensions()
yield return "ace";
}

public override bool IsArchive(
Stream stream,
string? password = null,
int bufferSize = ReaderOptions.DefaultBufferSize
)
public override bool IsArchive(Stream stream, string? password = null)
{
return AceHeader.IsArchive(stream);
}
Expand Down
6 changes: 1 addition & 5 deletions src/SharpCompress/Factories/ArcFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ public override IEnumerable<string> GetSupportedExtensions()
yield return "arc";
}

public override bool IsArchive(
Stream stream,
string? password = null,
int bufferSize = ReaderOptions.DefaultBufferSize
)
public override bool IsArchive(Stream stream, string? password = null)
{
//You may have to use some(paranoid) checks to ensure that you actually are
//processing an ARC file, since other archivers also adopted the idea of putting
Expand Down
6 changes: 1 addition & 5 deletions src/SharpCompress/Factories/ArjFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ public override IEnumerable<string> GetSupportedExtensions()
yield return "arj";
}

public override bool IsArchive(
Stream stream,
string? password = null,
int bufferSize = ReaderOptions.DefaultBufferSize
)
public override bool IsArchive(Stream stream, string? password = null)
{
return ArjHeader.IsArchive(stream);
}
Expand Down
8 changes: 2 additions & 6 deletions src/SharpCompress/Factories/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ public static void RegisterFactory(Factory factory)
public abstract IEnumerable<string> GetSupportedExtensions();

/// <inheritdoc/>
public abstract bool IsArchive(
Stream stream,
string? password = null,
int bufferSize = ReaderOptions.DefaultBufferSize
);
public abstract bool IsArchive(Stream stream, string? password = null);

/// <inheritdoc/>
public virtual FileInfo? GetFilePart(int index, FileInfo part1) => null;
Expand All @@ -82,7 +78,7 @@ out IReader? reader
{
long pos = ((IStreamStack)stream).GetPosition();

if (IsArchive(stream, options.Password, options.BufferSize))
if (IsArchive(stream, options.Password))
{
((IStreamStack)stream).StackSeek(pos);
reader = readerFactory.OpenReader(stream, options);
Expand Down
7 changes: 2 additions & 5 deletions src/SharpCompress/Factories/GZipFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ public override IEnumerable<string> GetSupportedExtensions()
}

/// <inheritdoc/>
public override bool IsArchive(
Stream stream,
string? password = null,
int bufferSize = ReaderOptions.DefaultBufferSize
) => GZipArchive.IsGZipFile(stream);
public override bool IsArchive(Stream stream, string? password = null) =>
GZipArchive.IsGZipFile(stream);

#endregion

Expand Down
6 changes: 1 addition & 5 deletions src/SharpCompress/Factories/IFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ public interface IFactory
/// </summary>
/// <param name="stream">A stream, pointing to the beginning of the archive.</param>
/// <param name="password">optional password</param>
bool IsArchive(
Stream stream,
string? password = null,
int bufferSize = ReaderOptions.DefaultBufferSize
);
bool IsArchive(Stream stream, string? password = null);

/// <summary>
/// From a passed in archive (zip, rar, 7z, 001), return all parts.
Expand Down
7 changes: 2 additions & 5 deletions src/SharpCompress/Factories/RarFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ public override IEnumerable<string> GetSupportedExtensions()
}

/// <inheritdoc/>
public override bool IsArchive(
Stream stream,
string? password = null,
int bufferSize = ReaderOptions.DefaultBufferSize
) => RarArchive.IsRarFile(stream);
public override bool IsArchive(Stream stream, string? password = null) =>
RarArchive.IsRarFile(stream);

/// <inheritdoc/>
public override FileInfo? GetFilePart(int index, FileInfo part1) =>
Expand Down
7 changes: 2 additions & 5 deletions src/SharpCompress/Factories/SevenZipFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ public override IEnumerable<string> GetSupportedExtensions()
}

/// <inheritdoc/>
public override bool IsArchive(
Stream stream,
string? password = null,
int bufferSize = ReaderOptions.DefaultBufferSize
) => SevenZipArchive.IsSevenZipFile(stream);
public override bool IsArchive(Stream stream, string? password = null) =>
SevenZipArchive.IsSevenZipFile(stream);

#endregion

Expand Down
7 changes: 2 additions & 5 deletions src/SharpCompress/Factories/TarFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,8 @@ public override IEnumerable<string> GetSupportedExtensions()
}

/// <inheritdoc/>
public override bool IsArchive(
Stream stream,
string? password = null,
int bufferSize = ReaderOptions.DefaultBufferSize
) => TarArchive.IsTarFile(stream);
public override bool IsArchive(Stream stream, string? password = null) =>
TarArchive.IsTarFile(stream);

#endregion

Expand Down
7 changes: 2 additions & 5 deletions src/SharpCompress/Factories/ZStandardFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ public override IEnumerable<string> GetSupportedExtensions()
yield return "zstd";
}

public override bool IsArchive(
Stream stream,
string? password = null,
int bufferSize = 65536
) => ZStandardStream.IsZStandard(stream);
public override bool IsArchive(Stream stream, string? password = null) =>
ZStandardStream.IsZStandard(stream);
}
Loading