Oakrey.Files
5.0.0
dotnet add package Oakrey.Files --version 5.0.0
NuGet\Install-Package Oakrey.Files -Version 5.0.0
<PackageReference Include="Oakrey.Files" Version="5.0.0" />
<PackageVersion Include="Oakrey.Files" Version="5.0.0" />
<PackageReference Include="Oakrey.Files" />
paket add Oakrey.Files --version 5.0.0
#r "nuget: Oakrey.Files, 5.0.0"
#:package Oakrey.Files@5.0.0
#addin nuget:?package=Oakrey.Files&version=5.0.0
#tool nuget:?package=Oakrey.Files&version=5.0.0
Oakrey.Files
Utilities for file naming, gzip compression and INI file handling.
Installation
dotnet add package Oakrey.Files
Package Manager Console:
Install-Package Oakrey.Files
File Names
FileNameGenerator creates names using predefined policies such as date/time, compact date/time, ticks, hexadecimal ticks, GUID and incremental values.
string name = FileNameGenerator.GetFileName("report", "txt", FileNamingPolicy.Incremental, string.Empty, 1);
// report_1.txt
For untrusted input, prefer the safe APIs. They replace path separators and invalid filename characters, normalize extensions and avoid Windows reserved device names.
string safeName = FileNameGenerator.GetSafeFileName("..\\unsafe/name", ".txt", FileNamingPolicy.Incremental, string.Empty, 1);
string safePath = FileNameGenerator.GetSafePathPath(folder, "..\\unsafe/name", ".txt", FileNamingPolicy.Incremental, string.Empty, 1);
FileNameSource stores naming settings and advances the incremental counter in a thread-safe way.
FileNameSource source = new(folder, "report", "txt", FileNamingPolicy.Incremental, string.Empty, 0);
string firstPath = source.GetSafeFilePath();
string secondPath = source.GetSafeFilePath();
GZip Compression
ZipCompression supports byte arrays, streams and files.
byte[] compressed = ZipCompression.Zip(data);
byte[] restored = ZipCompression.Unzip(compressed);
ZipCompression.Zip("input.txt", "output.gz");
ZipCompression.Unzip("output.gz", "restored.txt");
When decompressing untrusted data, set maxDecompressedBytes to reduce zip-bomb risk.
byte[] restored = ZipCompression.Unzip(compressed, maxDecompressedBytes: 10 * 1024 * 1024);
File destinations create missing directories automatically.
Basic INI Files
Oakrey.Files.Ini provides a simple key/value INI model.
IniFile ini = await IniReader.LoadAsync(new FileInfo("settings.ini"), CancellationToken.None);
ini.SetValue("app", "theme", "dark");
ini.SaveAtomic(new FileInfo("settings.ini"));
SaveAtomic writes through a temporary file and replaces the destination after a successful write.
Extended INI Files
Oakrey.Files.Ini.Extended preserves comments, blank lines, section inline comments and entry inline comments.
IniExtendedFile ini = Oakrey.Files.Ini.Extended.IniReader.Read(new FileInfo("settings.ini"));
ini.Set("app", "theme", "dark", "; user preference");
ini.SaveAtomic(new FileInfo("settings.ini"));
Project Information
- Author: Oakrey
- Company: Oakrey (Website)
- License: MIT
- Repository: Common
- NuGet: Oakrey.Files
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Oakrey.Guards (>= 5.0.0)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Oakrey.Files:
| Package | Downloads |
|---|---|
|
Oakrey.Applications.CustomLogging
A flexible and extensible .NET library for custom logging, supporting multiple logging engines, log broadcasting, and contextual logging with file path customization. |
|
|
Oakrey.Applications.Trace
A .NET library for tracing application activities to files. Provides ITracer with start/stop control, real-time status and elapsed-time observables (Rx), configurable file paths and naming policies, synchronized UTF-8 file writing, monotonic elapsed-time measurement, and integration with Oakrey.Telemetry and Oakrey.Log.Abstractions. |
|
|
Oakrey.Applications.Reporting
A .NET 11 library for structured, lifecycle-driven reporting. Defines IReporter and IReportConsumer generics with a TStatus enum, supporting report/block/item lifecycle events, evidence attachment, key-value metadata, and file output via FileReporter. RunnableReporter fans out to multiple consumers simultaneously. |
|
|
Oakrey.Applications.FileParsing.Ini
Specialized file parsing library for INI configuration files. Built on FileParsing framework with automatic parsing, reactive updates, and file browsing integration. Features auto-load support, observable patterns, and seamless integration with Oakrey.Files INI reader. |
GitHub repositories
This package is not used by any popular GitHub repositories.