JBlam.Collections.Streams 0.0.1-testing

This is a prerelease version of JBlam.Collections.Streams.
dotnet add package JBlam.Collections.Streams --version 0.0.1-testing
                    
NuGet\Install-Package JBlam.Collections.Streams -Version 0.0.1-testing
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JBlam.Collections.Streams" Version="0.0.1-testing" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JBlam.Collections.Streams" Version="0.0.1-testing" />
                    
Directory.Packages.props
<PackageReference Include="JBlam.Collections.Streams" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add JBlam.Collections.Streams --version 0.0.1-testing
                    
#r "nuget: JBlam.Collections.Streams, 0.0.1-testing"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package JBlam.Collections.Streams@0.0.1-testing
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=JBlam.Collections.Streams&version=0.0.1-testing&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=JBlam.Collections.Streams&version=0.0.1-testing&prerelease
                    
Install as a Cake Tool

JBlam's Stream query API

It's kind of like Linq, but for streams.

See the runtime's github issue which has some discussion about basically this topic.

Why

I keep producing these silly tedious throwaway implementations of "truncating stream" mainly in test projects.

In this repo, you can also find some stream assertions, which I may want to spin out into an assertion project at some point.

ReadStream

A mostly-virtual Stream, where the only fully-abstract API point is int Read(Span<byte>).

  • ValueTask<int> ReadAsync(Memory<byte>, CancellationToken) virtually delegates to the sync method, but you're most welcome to override it.
  • virtual overrides of Write, Flush, Seek, Position, and Length all throw NotImplementedException
  • All the "old style" (byte[], int, int) methods are sealed and delegate to the Span and Memory methods.

Delegate and factory methods

Factory methods are on the static JBlam.Collections.Streams.StreamCreate class.

That's a terrible name, but it'd suck if I follow the Linq convention for IEnmerable and IObservable I'd have a class called Stream, which would cause issues for people who using System.IO, which is just about everyone.

  • Create(IEnumerable<Memory<byte>>) and Create(IAsyncEnumerable<Memory<byte>>) build a stream out of enumerated segments. The latter may only be read asynchronously: Read(Span<byte>) throws NotSupportedException.

  • Create(Func<long,Span<byte>,int>)* and the equivalent async (ValueTask-returning) build a stream which invokes the delegate on each Read call.

  • Empty provides an empty stream.

    * Formally, I made a custom delegate SpanWriteAtPosition because it's not legal to put ref-structs like Span<byte> in generic type parameters.

Functional methods

Extension methods in the same StreamCreate class as above.

  • Take works like the Linq overload Enumerable.Take<T>(this IEnumerable<T>, Range), except I let you use multiple Range args. Requires the source CanSeek and expect Length to not throw. I consider "skip" to be redundant.
  • Append, Prepend, Join can concatenate streams.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.1-testing 106 5/10/2025