Skip to content

Add SkipPadding to BinaryWriterExtensions and fix missing guard in BinaryReaderExtensions#36

Merged
Tyrrrz merged 5 commits intoprimefrom
copilot/add-skippadding-to-binarywriter
Apr 15, 2026
Merged

Add SkipPadding to BinaryWriterExtensions and fix missing guard in BinaryReaderExtensions#36
Tyrrrz merged 5 commits intoprimefrom
copilot/add-skippadding-to-binarywriter

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 15, 2026

BinaryWriter lacked a SkipPadding counterpart to the existing BinaryReader.SkipPadding. Additionally, BinaryReaderExtensions.SkipPadding was missing an argument guard, which could cause a divide-by-zero for non-positive boundaryBytes values.

Changes

  • BinaryWriterExtensions — adds SkipPadding(int boundaryBytes = 4): writes 0x00 bytes until BaseStream.Position is aligned to the given boundary. Includes a guard against non-positive boundaryBytes to prevent divide-by-zero / infinite loops.
  • BinaryReaderExtensions — adds the same ArgumentOutOfRangeException guard to the existing SkipPadding for consistency and to prevent divide-by-zero on non-positive boundaryBytes.
  • BinaryWriterExtensionsTests — adds tests for the unaligned and already-aligned cases.

Usage

using var writer = new BinaryWriter(stream);
writer.Write((byte)0x01); // position = 1
writer.SkipPadding(boundaryBytes: 4); // writes 3 zero bytes → position = 4

Agent-Logs-Url: https://github.com/Tyrrrz/PowerKit/sessions/8428ef47-c8d0-4c5c-84c7-c003794f1c24

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
@Tyrrrz Tyrrrz added the enhancement New feature or request label Apr 15, 2026
@Tyrrrz Tyrrrz marked this pull request as ready for review April 15, 2026 19:05
Copilot AI review requested due to automatic review settings April 15, 2026 19:05
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.08%. Comparing base (1a2fcb3) to head (cad6506).
⚠️ Report is 1 commits behind head on prime.

Files with missing lines Patch % Lines
PowerKit/Extensions/BinaryReaderExtensions.cs 0.00% 1 Missing and 1 partial ⚠️
PowerKit/Extensions/BinaryWriterExtensions.cs 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            prime      #36      +/-   ##
==========================================
- Coverage   94.28%   94.08%   -0.20%     
==========================================
  Files          76       76              
  Lines        1469     1489      +20     
  Branches      121      124       +3     
==========================================
+ Hits         1385     1401      +16     
- Misses         65       67       +2     
- Partials       19       21       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Tyrrrz
Copy link
Copy Markdown
Owner

Tyrrrz commented Apr 15, 2026

@copilot formatting failure

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a BinaryWriter counterpart to the existing BinaryReader.SkipPadding, enabling callers to write zero-byte padding until the underlying stream position is aligned to a specified boundary.

Changes:

  • Add BinaryWriterExtensions.SkipPadding(int boundaryBytes = 4) to write 0x00 bytes until BaseStream.Position aligns to boundaryBytes.
  • Add tests covering the unaligned and already-aligned scenarios for SkipPadding.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
PowerKit/Extensions/BinaryWriterExtensions.cs Introduces SkipPadding for BinaryWriter with argument validation.
PowerKit.Tests/BinaryWriterExtensionsTests.cs Adds tests verifying padding behavior for aligned/unaligned positions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PowerKit/Extensions/BinaryWriterExtensions.cs Outdated
Comment thread PowerKit/Extensions/BinaryWriterExtensions.cs
Comment thread PowerKit/Extensions/BinaryWriterExtensions.cs Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Tyrrrz
Copy link
Copy Markdown
Owner

Tyrrrz commented Apr 15, 2026

@copilot do we have the same argument check in the other SkipPadding method?

Copilot AI and others added 2 commits April 15, 2026 19:12
…ywriter' into copilot/add-skippadding-to-binarywriter

Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 15, 2026

@copilot formatting failure

Fixed in 62c3ffd — ran CSharpier on the file and merged the single-argument ArgumentOutOfRangeException form you preferred. The build now passes the format check.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 15, 2026

@copilot do we have the same argument check in the other SkipPadding method?

No — BinaryReaderExtensions.SkipPadding didn't have the guard, so a non-positive boundaryBytes would cause a divide-by-zero. Added the same check in cad6506.

Copilot AI changed the title Add SkipPadding to BinaryWriterExtensions Add SkipPadding to BinaryWriterExtensions and fix missing guard in BinaryReaderExtensions Apr 15, 2026
@Tyrrrz Tyrrrz merged commit c523665 into prime Apr 15, 2026
7 checks passed
@Tyrrrz Tyrrrz deleted the copilot/add-skippadding-to-binarywriter branch April 15, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants