Skip to content

Extract StreamPortal utility from Ressy into PowerKit - #89

Merged
Tyrrrz merged 3 commits into
primefrom
copilot/extract-streamportal-utility
Jul 20, 2026
Merged

Extract StreamPortal utility from Ressy into PowerKit#89
Tyrrrz merged 3 commits into
primefrom
copilot/extract-streamportal-utility

Conversation

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Ports StreamPortal from Ressy into PowerKit as a first-class public utility.

Changes

  • StreamPortal.cs — new public class that captures a stream position and exposes Jump(), which seeks to that position and returns an IDisposable that restores the original position on dispose. Constructor guards against non-seekable streams and negative positions.
  • StreamExtensions.cs — two new CreatePortal extension methods on Stream: one targeting the current position, one accepting an explicit offset.

Usage

using var stream = File.OpenRead("data.bin");
stream.Seek(100, SeekOrigin.Begin);

var portal = stream.CreatePortal(); // saves position 100

// later...
using (portal.Jump())
{
    // stream is at 100 here
    var header = reader.ReadBytes(16);
} // stream restored to wherever it was before Jump()

@Tyrrrz Tyrrrz added the enhancement New feature or request label Jul 20, 2026
@Tyrrrz
Tyrrrz marked this pull request as ready for review July 20, 2026 18:00
Copilot AI review requested due to automatic review settings July 20, 2026 18:00
Comment thread PowerKit.Tests/StreamPortalTests.cs Outdated
Comment on lines +40 to +57
public void Jump_SeeksToPortalPosition_Test()
{
// Arrange
var data = new byte[] { 1, 2, 3, 4, 5 };
using var stream = new MemoryStream(data);
var portal = stream.CreatePortal(3);
stream.Seek(0, SeekOrigin.Begin);

// Act
using (portal.Jump())
{
// Assert
stream.Position.Should().Be(3);
}
}

[Fact]
public void Jump_RestoresPositionOnDispose_Test()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

These two tests can be merged @copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done — merged the two tests into Jump_SeeksToPortalPositionAndRestoresOnDispose_Test in commit Merge Jump_SeeksToPortalPosition and Jump_RestoresPositionOnDispose tests into one. The single test now asserts both that Jump() seeks to the portal position and that Dispose() restores the original position.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Ports the StreamPortal concept into PowerKit to provide a reusable utility for saving a stream position and temporarily jumping back to it with automatic restoration via IDisposable.

Changes:

  • Added StreamPortal public utility type for capturing a stream position and restoring it after a scoped jump.
  • Added Stream.CreatePortal() / Stream.CreatePortal(long) extension methods for convenient portal creation.
  • Added unit tests validating basic portal creation and jump/restore behavior.

Reviewed changes

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

File Description
PowerKit/StreamPortal.cs Introduces the StreamPortal type with position capture, validation, and Jump() restore semantics.
PowerKit/Extensions/StreamExtensions.cs Adds CreatePortal extension methods to construct StreamPortal instances from a Stream.
PowerKit.Tests/StreamPortalTests.cs Adds tests for portal creation and jump/restore behavior.

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

Comment thread PowerKit/Extensions/StreamExtensions.cs
Comment thread PowerKit.Tests/StreamPortalTests.cs Outdated
Copilot AI requested a review from Tyrrrz July 20, 2026 18:07
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.43%. Comparing base (7501f41) to head (c71284c).

Files with missing lines Patch % Lines
PowerKit/StreamPortal.cs 92.30% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            prime      #89      +/-   ##
==========================================
+ Coverage   86.35%   86.43%   +0.08%     
==========================================
  Files          74       75       +1     
  Lines        1253     1268      +15     
  Branches      234      235       +1     
==========================================
+ Hits         1082     1096      +14     
  Misses        121      121              
- Partials       50       51       +1     

☔ View full report in Codecov by Harness.
📢 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.

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