Soenneker.Extensions.Spans.Readonly.Bytes
11.0.108
Prefix Reserved
dotnet add package Soenneker.Extensions.Spans.Readonly.Bytes --version 11.0.108
NuGet\Install-Package Soenneker.Extensions.Spans.Readonly.Bytes -Version 11.0.108
<PackageReference Include="Soenneker.Extensions.Spans.Readonly.Bytes" Version="11.0.108" />
<PackageVersion Include="Soenneker.Extensions.Spans.Readonly.Bytes" Version="11.0.108" />
<PackageReference Include="Soenneker.Extensions.Spans.Readonly.Bytes" />
paket add Soenneker.Extensions.Spans.Readonly.Bytes --version 11.0.108
#r "nuget: Soenneker.Extensions.Spans.Readonly.Bytes, 11.0.108"
#:package Soenneker.Extensions.Spans.Readonly.Bytes@11.0.108
#addin nuget:?package=Soenneker.Extensions.Spans.Readonly.Bytes&version=11.0.108
#tool nuget:?package=Soenneker.Extensions.Spans.Readonly.Bytes&version=11.0.108
Soenneker.Extensions.Spans.Readonly.Bytes
Allocation-conscious SHA-256, ASCII comparison, and content-sniffing helpers for ReadOnlySpan<byte>.
Installation
dotnet add package Soenneker.Extensions.Spans.Readonly.Bytes
SHA-256 as hexadecimal text
using Soenneker.Extensions.Spans.Readonly.Bytes;
ReadOnlySpan<byte> data = "payload"u8;
string upper = data.ToSha256Hex();
string lower = data.ToSha256Hex(upperCase: false);
Span<char> destination = stackalloc char[64];
bool written = data.TryWriteSha256Hex(destination, upperCase: false, out int charsWritten);
ToSha256Hex() returns exactly 64 characters. TryWriteSha256Hex() avoids the result-string allocation, requires a destination of at least 64 characters, and reports charsWritten = 0 without modifying the destination when it is too small.
Classify an unknown payload
using Soenneker.Enums.ContentKinds;
using Soenneker.Extensions.Spans.Readonly.Bytes;
ReadOnlySpan<byte> payload = " {\"id\": 42}"u8;
ContentKind kind = payload.Classify();
bool looksLikeJson = payload.LooksLikeJson();
Classification is deliberately a cheap sniff, not parsing or validation. It examines at most the first 512 bytes, skips a leading UTF-8 BOM, treats a null byte or a high density of control bytes as binary, and otherwise uses the first non-whitespace byte to choose JSON, XML/HTML, or text. JSON scalar prefixes such as a quote, digit, -, t, f, or n are recognized.
Use a real JSON/XML parser before trusting or processing untrusted content. UTF-8 validity is not checked, and XmlOrHtml does not distinguish the two formats.
ASCII helpers
bool equal = "CONTENT-TYPE"u8.Utf8AsciiEqualsIgnoreCase("content-type"u8);
bool containsUtf8 = "café"u8.ContainsNonAscii();
Utf8AsciiEqualsIgnoreCase() compares ASCII letters without culture rules. It does not validate that either input is ASCII; non-letter bytes must match exactly. ContainsNonAscii() simply detects bytes from 0x80 through 0xFF and does not validate UTF-8.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Soenneker.Enums.ContentKinds (>= 11.0.85)
- Soenneker.Hashing.Sha256 (>= 11.0.21)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Extensions.Spans.Readonly.Bytes:
| Package | Downloads |
|---|---|
|
Soenneker.Extensions.Spans.Readonly.Chars
A collection of helpful ReadOnlySpan (char) extension methods |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.108 | 0 | 11/15/2026 |
| 11.0.107 | 12,610 | 11/11/2026 |
| 11.0.106 | 6,148 | 11/11/2026 |
| 11.0.105 | 27,610 | 11/10/2026 |
| 11.0.104 | 61,622 | 11/3/2026 |
| 11.0.103 | 23,629 | 11/2/2026 |
| 11.0.102 | 346 | 11/2/2026 |
| 11.0.101 | 19,046 | 10/26/2026 |
| 11.0.100 | 166 | 10/26/2026 |
| 4.0.99 | 538 | 10/26/2026 |
| 4.0.98 | 162,572 | 10/15/2026 |
| 4.0.97 | 109 | 10/15/2026 |
| 4.0.96 | 103 | 10/14/2026 |
| 4.0.94 | 180 | 10/14/2026 |
| 4.0.93 | 150 | 10/14/2026 |
| 4.0.92 | 2,901 | 10/14/2026 |
| 4.0.86 | 5,933 | 10/13/2026 |
| 4.0.85 | 119 | 10/12/2026 |
| 4.0.83 | 8,961 | 10/12/2026 |
| 4.0.82 | 34,805 | 10/12/2026 |
Update dependency Soenneker.Enums.ContentKinds to 11.0.85 (#321)