SingularFrameworkCore.Repository.FileSystem.BinaryFile 0.2.0-beta

This is a prerelease version of SingularFrameworkCore.Repository.FileSystem.BinaryFile.
dotnet add package SingularFrameworkCore.Repository.FileSystem.BinaryFile --version 0.2.0-beta                
NuGet\Install-Package SingularFrameworkCore.Repository.FileSystem.BinaryFile -Version 0.2.0-beta                
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="SingularFrameworkCore.Repository.FileSystem.BinaryFile" Version="0.2.0-beta" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SingularFrameworkCore.Repository.FileSystem.BinaryFile --version 0.2.0-beta                
#r "nuget: SingularFrameworkCore.Repository.FileSystem.BinaryFile, 0.2.0-beta"                
#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.
// Install SingularFrameworkCore.Repository.FileSystem.BinaryFile as a Cake Addin
#addin nuget:?package=SingularFrameworkCore.Repository.FileSystem.BinaryFile&version=0.2.0-beta&prerelease

// Install SingularFrameworkCore.Repository.FileSystem.BinaryFile as a Cake Tool
#tool nuget:?package=SingularFrameworkCore.Repository.FileSystem.BinaryFile&version=0.2.0-beta&prerelease                

SingularFrameworkCore.Repository.FileSystem.BinaryFile

A C# library that provides binary file storage implementation for the SingularFrameworkCore repository interface. This library offers both synchronous and asynchronous implementations for storing byte[] data in binary files.

Features

  • Binary File Storage: Simple implementation for storing byte[] data in binary files
  • Dual Implementation: Both synchronous (BinaryFileRepository) and asynchronous (BinaryFileRepositoryAsync) versions
  • CRUD Operations: Full support for Create, Read, Update, and Delete operations
  • Path Management: Secure file path handling
  • Exception Handling: Custom exceptions for common scenarios

Installation

The package is available on NuGet. To install it, use the following command:

Install-Package SingularFrameworkCore.Repository.FileSystem.BinaryFile

Or using the .NET CLI:

dotnet add package SingularFrameworkCore.Repository.FileSystem.BinaryFile

Usage

Synchronous Implementation

using SingularFrameworkCore.Repository.FileSystem.BinaryFile;

// Create an instance with a file path
var repository = new BinaryFileRepository("path/to/your/file.bin");

// Create
repository.Create(Encoding.UTF8.GetBytes("Hello, World!"));

// Read
byte[] content = repository.Read();

// Update
repository.Update(Encoding.UTF8.GetBytes("Updated content"));

// Delete
repository.Delete();

Asynchronous Implementation

using SingularFrameworkCore.Repository.FileSystem.BinaryFile;

// Create an instance with a file path
var repository = new BinaryFileRepositoryAsync("path/to/your/file.bin");

// Create
await repository.Create(Encoding.UTF8.GetBytes("Hello, World!"));

// Read
byte[] content = await repository.Read();

// Update
await repository.Update(Encoding.UTF8.GetBytes("Updated content"));

// Delete
await repository.Delete();

Integration with SingularFrameworkCore

This library implements the ISingularCrudRepository<byte[]> and ISingularCrudAsyncRepository<byte[]> interfaces from SingularFrameworkCore, making it perfect for use with the Singular pipeline:

var singular = new Singular<MyClass, byte[]>(
    new BinaryFileRepository("data.bin"), // or BinaryFileRepositoryAsync
    serializer,
    preProcessors,
    postProcessors
);

Exception Handling

The library includes a custom exception:

  • BinaryFileRepositoryFileAlreadyExistsException: Thrown when attempting to create a file that already exists
try 
{
    repository.Create(Encoding.UTF8.GetBytes("content"));
}
catch (BinaryFileRepositoryFileAlreadyExistsException ex)
{
    // Handle the case where the file already exists
}

Requirements

  • .NET Standard 8.0+
  • SingularFrameworkCore

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Author

Made by Mohammad Ayaad MohammadAyaad

Original Project

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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.2.0-beta 40 2/15/2025
0.1.0-alpha 40 1/30/2025