From 513cd4f905ca854e2837d522dfdfd8d562689dc9 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Wed, 22 Oct 2025 10:16:45 +0100 Subject: [PATCH] some AI suggestions --- src/SharpCompress/Archives/Zip/ZipArchive.cs | 2 +- src/SharpCompress/Utility.cs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/SharpCompress/Archives/Zip/ZipArchive.cs b/src/SharpCompress/Archives/Zip/ZipArchive.cs index f599d400..35b8e0cb 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchive.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchive.cs @@ -43,7 +43,7 @@ public class ZipArchive : AbstractWritableArchive /// public static ZipArchive Open(string filePath, ReaderOptions? readerOptions = null) { - filePath.NotNull(nameof(filePath)); + filePath.NotNullOrEmpty(nameof(filePath)); return Open(new FileInfo(filePath), readerOptions ?? new ReaderOptions()); } diff --git a/src/SharpCompress/Utility.cs b/src/SharpCompress/Utility.cs index 69a1fb9b..19e132d5 100644 --- a/src/SharpCompress/Utility.cs +++ b/src/SharpCompress/Utility.cs @@ -10,6 +10,7 @@ namespace SharpCompress; internal static class Utility { + //80kb is a good industry standard temporary buffer size private const int TEMP_BUFFER_SIZE = 81920; private static readonly HashSet invalidChars = new(Path.GetInvalidFileNameChars()); @@ -214,7 +215,8 @@ internal static class Utility { var iterations = 0; long total = 0; - while (ReadTransferBlock(source, array, out var count)) + int count; + while ((count = source.Read(array, 0, array.Length)) != 0) { total += count; destination.Write(array, 0, count); @@ -229,12 +231,10 @@ internal static class Utility } } - private static bool ReadTransferBlock(Stream source, byte[] array, out int count) => - (count = source.Read(array, 0, array.Length)) != 0; - - private static bool ReadTransferBlock(Stream source, byte[] array, int size, out int count) + private static bool ReadTransferBlock(Stream source, byte[] array, int maxSize, out int count) { - if (size > array.Length) + var size = maxSize; + if (maxSize > array.Length) { size = array.Length; }