[PR #1165] (Release) Buffer size consolidation #1605

Open
opened 2026-01-29 22:21:22 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/adamhathcock/sharpcompress/pull/1165

State: closed
Merged: Yes


This pull request standardizes and centralizes the default buffer size used for stream operations across the codebase by introducing a new Constants.BufferSize value. It also simplifies method signatures for archive detection by removing the bufferSize parameter where possible, and updates all relevant usages to reference the new constant. These changes improve consistency, maintainability, and make it easier to change the buffer size globally in the future.

Buffer Size Centralization and Usage Updates:

  • Introduced Constants.BufferSize (default 81920 bytes) in src/SharpCompress/Common/Constants.cs, replacing scattered magic numbers and previous constants for buffer sizes throughout the codebase.
  • Updated all stream copying operations (e.g., in IArchiveEntryExtensions.cs, TarArchive.cs, AbstractReader.cs) to use Constants.BufferSize instead of hardcoded values or previous constants. [1] [2] [3] [4]

API Simplification and Consistency:

  • Removed the bufferSize parameter from IsArchive and related methods in interfaces and factories (e.g., IFactory, Factory, and all concrete factory classes), simplifying their signatures and usage. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]
  • Updated all usages of IsArchive, IsZipFile, and similar methods to match the new signatures, removing the buffer size argument and ensuring consistent use of Constants.BufferSize internally. [1] [2] [3] [4]

Legacy Constant Cleanup:

  • Removed the obsolete DefaultBufferSize constant from ReaderOptions and updated its usage to reference Constants.BufferSize instead. [1] [2]
  • Removed other redundant buffer size constants and magic numbers, such as TEMP_BUFFER_SIZE in Utility.cs and BufferSize in IArchiveEntryExtensions.cs. [1] [2]
**Original Pull Request:** https://github.com/adamhathcock/sharpcompress/pull/1165 **State:** closed **Merged:** Yes --- This pull request standardizes and centralizes the default buffer size used for stream operations across the codebase by introducing a new `Constants.BufferSize` value. It also simplifies method signatures for archive detection by removing the `bufferSize` parameter where possible, and updates all relevant usages to reference the new constant. These changes improve consistency, maintainability, and make it easier to change the buffer size globally in the future. **Buffer Size Centralization and Usage Updates:** * Introduced `Constants.BufferSize` (default 81920 bytes) in `src/SharpCompress/Common/Constants.cs`, replacing scattered magic numbers and previous constants for buffer sizes throughout the codebase. * Updated all stream copying operations (e.g., in `IArchiveEntryExtensions.cs`, `TarArchive.cs`, `AbstractReader.cs`) to use `Constants.BufferSize` instead of hardcoded values or previous constants. [[1]](diffhunk://#diff-61084e55d70b594ef97e944a0bc645b95f63a1854f75f17a038ab224850cfa0cL31-R29) [[2]](diffhunk://#diff-61084e55d70b594ef97e944a0bc645b95f63a1854f75f17a038ab224850cfa0cL54-R52) [[3]](diffhunk://#diff-7f2eb9160ad6da95a3247f13cfb74c5556ae75ba12daaf9eeeab0edd8cd965d0L183-R183) [[4]](diffhunk://#diff-083fd66e1dab6e8c43abba168d79aad52ea814263e77dcca1eb34f7ce342842fL265-R281) **API Simplification and Consistency:** * Removed the `bufferSize` parameter from `IsArchive` and related methods in interfaces and factories (e.g., `IFactory`, `Factory`, and all concrete factory classes), simplifying their signatures and usage. [[1]](diffhunk://#diff-905353d54177b657dfcdff05cd3ea03755ea96228aef3e5107c3467dd58be18dL39-R39) [[2]](diffhunk://#diff-8bd4092c86ee37af196973dc7e57607eec5d3d1b0508b811d996977de62c3518L54-R54) [[3]](diffhunk://#diff-8bd4092c86ee37af196973dc7e57607eec5d3d1b0508b811d996977de62c3518L85-R81) [[4]](diffhunk://#diff-ed73ecc9390f716d464db47b9348155cd299e896469da34e16fdfa2ecd1aa47bL25-R25) [[5]](diffhunk://#diff-800f1b0c584eba50b849faa713b1d38c49e98276a9c84787069a948f58d85606L26-R33) [[6]](diffhunk://#diff-5f18bdabcff95ce9d36a774973a6f0e1e1fb01a70823556881455e9f9507c4abL25-R25) [[7]](diffhunk://#diff-411c372728302efc6962fc0fe053b1ad2225eba6de5bf86edfc53d123e25bcedL43-R44) [[8]](diffhunk://#diff-26f9a8c602e82b9ca394ff349d386f64d45d58a99d653b746abd3f8afeffe388L32-R33) [[9]](diffhunk://#diff-cd42deea8cb3c5956d1525a00343b0bee9ad46aa4d9dd62909ba9f5f5fe493cdL31-R32) [[10]](diffhunk://#diff-427819bd6e62926e10f46ac47acd569eab506b83e9d46bb3d729779a931238a6L56-R57) [[11]](diffhunk://#diff-43c2d53c213abc9b498cac18c871fb4200879d569f3e64964fbb752e6ba0b9eaL23-R24) [[12]](diffhunk://#diff-5dcd6c58655a0efb67027c2f36dfbf0bc885cf015998f07a658aaea87944a0d4L42-R53) [[13]](diffhunk://#diff-5dcd6c58655a0efb67027c2f36dfbf0bc885cf015998f07a658aaea87944a0d4L72-R68) [[14]](diffhunk://#diff-14afa030115e58257f705ec89e4ff1f3f81c9faa64fc5c1ae6f4ec1671f6c0f6L17-R18) * Updated all usages of `IsArchive`, `IsZipFile`, and similar methods to match the new signatures, removing the buffer size argument and ensuring consistent use of `Constants.BufferSize` internally. [[1]](diffhunk://#diff-22b8bc5a3d713f2404d058a5fddfba4cec7f175d67a00be88fe4f96da36f7d18L169-R176) [[2]](diffhunk://#diff-fdeace22df51f39be3461b03ffceb3ae6b63a006fa2f3428c3a4df6728354dc8L127-R147) [[3]](diffhunk://#diff-fdeace22df51f39be3461b03ffceb3ae6b63a006fa2f3428c3a4df6728354dc8L180-R176) [[4]](diffhunk://#diff-fdeace22df51f39be3461b03ffceb3ae6b63a006fa2f3428c3a4df6728354dc8L232-R217) **Legacy Constant Cleanup:** * Removed the obsolete `DefaultBufferSize` constant from `ReaderOptions` and updated its usage to reference `Constants.BufferSize` instead. [[1]](diffhunk://#diff-13748160e4b6d80308b56fe7dd47fd436e1f6bcc739123932ed596228b9b1188L8-L9) [[2]](diffhunk://#diff-13748160e4b6d80308b56fe7dd47fd436e1f6bcc739123932ed596228b9b1188L19-R17) * Removed other redundant buffer size constants and magic numbers, such as `TEMP_BUFFER_SIZE` in `Utility.cs` and `BufferSize` in `IArchiveEntryExtensions.cs`. [[1]](diffhunk://#diff-10a4a0ed7b02894cae94a77846c2bdd1a83e6a58898ccdf9d9053669170d378bL14-L15) [[2]](diffhunk://#diff-61084e55d70b594ef97e944a0bc645b95f63a1854f75f17a038ab224850cfa0cL12-L13)
claunia added the pull-request label 2026-01-29 22:21:22 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1605