GenericReader 3.0.0

dotnet add package GenericReader --version 3.0.0
                    
NuGet\Install-Package GenericReader -Version 3.0.0
                    
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="GenericReader" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GenericReader" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="GenericReader" />
                    
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 GenericReader --version 3.0.0
                    
#r "nuget: GenericReader, 3.0.0"
                    
#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 GenericReader@3.0.0
                    
#: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=GenericReader&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=GenericReader&version=3.0.0
                    
Install as a Cake Tool

<div align="center">

🚀 GenericReader

A generic, extensible binary reader for .NET
Effortlessly read from files, streams, buffers, or spans with a single unified API.

GitHub release NuGet NuGet Downloads GitHub issues License

</div>


📦 Installation

Install via NuGet:

Install-Package GenericReader

✨ Features

  • Read from files, streams, buffers, and spans
  • Generic Read<T>() API for simplicity and flexibility
  • Lightweight and easy to integrate

🔧 Example Usage

using GenericReader;

// From file
using var fileReader = new GenericFileReader(@"C:\Test\Example.bin");
var numberFromFile = fileReader.Read<uint>();

// From stream
using var streamReader = new GenericStreamReader(GetStream());
var numberFromStream = streamReader.Read<uint>();

// From byte array
using var bufferReader = new GenericBufferReader(GetBuffer());
var numberFromBuffer = bufferReader.Read<uint>();

// From span
var spanReader = new GenericSpanReader(GetSpan());
var numberFromSpan = spanReader.Read<uint>();

🛡️ Corrupted Data

Every reader checks each read against the data before it reads or allocates anything, and all readers fail the same way:

Exception When
EndOfStreamException The data ends before the read does, or the read starts past the end (even when it reads zero bytes)
InvalidDataException The data contains a length that cannot be valid: a negative length prefix, an FString length whose byte count does not fit in an int, or a getter array larger than MaxArrayAllocationSize
ArgumentOutOfRangeException An argument is invalid, such as a negative length, a position or seek target outside of [0, max], or a negative MaxArrayAllocationSize

A read that fails does not move Position, with two exceptions:

  • A length prefix that was read before the failure stays read.
  • Reads made of several steps keep the steps that succeeded. The overloads with an offset keep their seek, and an array of FStrings or of getter elements keeps the elements it read.

Positions past the end are allowed, as with streams; reading there fails. After Dispose, the buffer, file and stream readers throw ObjectDisposedException for every read and every access to the position; Length stays available. Readers over memory return ReadOnlySpan<byte> and ReadOnlyMemory<byte> views of it. If a file or stream turns out shorter than the Length it had when the reader was created, the read throws EndOfStreamException, and the destination may hold part of the data.

ReadArray with a getter allocates the array before it reads any element, and an element may take no bytes at all, so its length cannot be checked against the data. MaxArrayAllocationSize limits the array size in bytes instead. The default is IGenericReader.DefaultMaxArrayAllocationSize, 256 MiB:

reader.MaxArrayAllocationSize = 64 * 1024 * 1024;
var entries = reader.ReadArray(() => new Entry(reader));

🤝 Contributing

Contributions are welcome and appreciated!

Whether it's fixing a typo, suggesting an improvement, or submitting a pull request — every bit helps.


📄 License

This project is licensed under the MIT License.


<div align="center">

⭐️ Star the repo if you find it useful!
Feel free to open an issue if you have any questions or feedback.

</div>

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on GenericReader:

Package Downloads
CUE4Parse

C# Parser for Unreal Engine packages & assets

EpicManifestParser

A .NET parser & downloader for EpicGames manifests

AbioticEditor.Core

The engine behind the Abiotic Factor save editor: byte-exact GVAS save reading/writing, the player/world/metadata save models, game-data catalogs (items, recipes, skills, quest flags), and the plugin host. The desktop app and CLI are thin front-ends over this library. Bundles the Apache-2.0 UeSaveGame.Json and CUE4Parse assemblies it builds against.

Usmap.NET

A .NET parser for .usmap files

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on GenericReader:

Repository Stars
FabianFG/CUE4Parse
GalaxySwapperOfficial/Galaxy-Swapper-v2
Revamp your Fortnite experience with our skin swapper designed for the latest version of Fortnite.