Lyo.IO.Temp 3.0.0

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

Lyo.IO.Temp

Session-scoped temp files and directories, with naming strategies and overflow policies.

Callers use IIOTempService and IIOTempSession. IOTempService and IOTempSession are the stock implementations. When the repo generates XML docs, IntelliSense repeats the same summaries as this README. Types that only implement those interfaces use <inheritdoc />.

Features

  • Sessions. IIOTempSession owns a set of temp files and dirs and deletes them when disposed.
  • One-offs. CreateFile / CreateDirectory without opening a session.
  • Pluggable storage. All I/O goes through Lyo.IO.FileSystem.IFileSystem. Default is LocalFileSystem (PathStyle.Host). Set IOTempServiceOptions.StorageKind to Memory for MemoryFileSystem (PathStyle.Posix), or register IFileSystem before AddIOTempService. Path combine/normalize/jail uses Lyo.Common.Core.Pathing.PathHelpers.
  • Naming. Guid, Sequential, Timestamp, RandomChars.
  • Overflow. When a per-file or total-size cap is crossed: ThrowException, DeleteOldest, or DeleteLargest.
  • Generator. session.Generator writes random-byte files, text/CSV/JSON, zips, and fake directory trees.
  • Events. Session: FileCreated / DirectoryCreated / FileWritten / FileAppended / FileDeleted / DirectoryDeleted / Overflow / Cleared / Disposed. Service: SessionCreated / SessionDisposed / one-off create and cleanup deletes.
  • Nested sessions. Child sessions whose root sits inside a parent session.
  • Inspection. Snapshots, byte totals, on-disk enumerations.
  • Keyed pools. GetOrCreateSession(key) for per-request or per-pipeline reuse.
  • Fluent option helpers. WithMaxFileSize / WithMaxTotalSize on options objects.
  • Test asserts. AssertFilesExist / AssertTotalSize on IIOTempSession.
  • Auto-cleanup. An IHostedService that calls Cleanup() on a timer.
  • Metrics. Session/file/cleanup counters when IMetrics is registered.

Examples

DI registration

// Add to DI
services.AddIOTempService(); // uses default options

// Or configure options
services.AddIOTempService(options =>
{
    options.DirectoryName = "my-app-temp";
    options.MaxTotalSizeBytes = 500 * 1024 * 1024; // 500 MB
});

// Add with automatic background cleanup
services.AddIOTempServiceWithAutoCleanup(
    cleanupInterval: TimeSpan.FromHours(1),
    initialDelay: TimeSpan.FromMinutes(5));

Sessions (preferred)

using var session = _ioTempService.CreateSession();

// Write your own data
var path = session.GetFilePath("report.pdf");
await File.WriteAllBytesAsync(path, reportBytes);

// Or create directly from data
var path2 = await session.CreateFileAsync(byteData);
var path3 = await session.CreateFileAsync(stream);

// Session dispose → all files/dirs cleaned up automatically

Generator

// Random-bytes files
var file = session.Generator.CreateRandomFile(FileSizeUnitInfo.Megabyte, 1);
var files = session.Generator.CreateRandomFiles(5, FileSizeUnitInfo.Kilobyte, 64);

// Named random files (name selector per index)
var named = session.Generator.CreateRandomFiles(3, 1024, i => $"chunk_{i}.bin");

// Structured content
var txt = session.Generator.CreateTextFile(lines: 100, charsPerLine: 80);
var csv = session.Generator.CreateCsvFile(rows: 500, columns: 10);
var json = session.Generator.CreateJsonFile(depth: 3, keysPerObject: 5);

// Zip archive
var zip = session.Generator.CreateZipFile(TempDirectorySpec.Flat(10, 1024));

// Simulated directory tree
var dir = session.Generator.SimulateDirectory(TempDirectorySpec.Flat(20, 512));

TempDirectorySpec

// Fluent builder
var spec = TempDirectorySpec.Builder()
    .WithFiles(5, FileSizeUnitInfo.Kilobyte, 4)
    .WithFileSizeSelector(i => (i + 1) * 512) // per-file size varies
    .WithSubdirectory(sub => sub.WithFiles(3, 256))
    .WithSubdirectory(TempDirectorySpec.Flat(2, 128))
    .Build();

// Randomised spec
var randomSpec = TempDirectorySpec.Random(
    minFiles: 3, maxFiles: 10,
    minSize: 512, maxSize: 4096);

Mutating a session

// Delete all tracked files/dirs, reset byte count
session.Clear();

// Copy an external file or directory into the session
var dest = session.CopyFrom("/path/to/external/file.csv");
var destDir = session.CopyFrom("/path/to/external/dir");

// Append data to an existing tracked file
session.AppendToFile(path, ReadOnlyMemory<byte>.Empty);
session.AppendToFile(path, "extra line\n");

Events

session.FileCreated += path => Console.WriteLine($"Created: {path}");
session.DirectoryCreated += path => Console.WriteLine($"Dir created: {path}");
session.FileWritten += path => Console.WriteLine($"Written: {path}");
session.FileAppended += path => Console.WriteLine($"Appended: {path}");
session.FileDeleted += path => Console.WriteLine($"Deleted: {path}");
session.DirectoryDeleted += path => Console.WriteLine($"Dir deleted: {path}");
session.Overflow += path => Console.WriteLine($"Evicted: {path}");
session.Cleared += path => Console.WriteLine($"Cleared: {path}");
session.Disposed += path => Console.WriteLine($"Disposed: {path}");

service.SessionCreated += path => Console.WriteLine($"Session: {path}");
service.SessionDisposed += path => Console.WriteLine($"Session gone: {path}");

Nested sessions

using var sub = session.CreateSubSession();
// sub is rooted inside session.SessionDirectory
// disposing session also removes all sub-session content

Inspection

long bytes = session.GetTotalBytesUsed();
var snapshot = session.GetSnapshot(); // TempSessionSnapshot: frozen view

var files = session.EnumerateFiles("*.csv"); // all .csv on disk (including untracked)
var dirs = session.EnumerateDirectories();

Keyed session pool

// Get or create a named session (same instance returned for same key)
var session = service.GetOrCreateSession("pipeline-A");

// With custom options for initial creation
var session = service.GetOrCreateSession("pipeline-A", new IOTempSessionOptions { MaxTotalSizeBytes = 100_000 });

// Release when done
service.ReleaseSession("pipeline-A");

// Service-level stats
IOTempServiceStats stats = service.GetStats();

Fluent option helpers

var sessionOptions = new IOTempSessionOptions()
    .WithMaxFileSize(FileSizeUnitInfo.Megabyte, 5)
    .WithMaxTotalSize(FileSizeUnitInfo.Gigabyte, 1);

Test assertions

session.AssertFilesExist(); // all tracked files exist on disk
session.AssertTotalSize(expectedBytes: 2048, toleranceBytes: 64);

One-offs (no session)

var path = _ioTempService.CreateFile();
var pathWithData = _ioTempService.CreateFile(byteData, "myfile.bin");
var dir = _ioTempService.CreateDirectory();

Cleanup

_ioTempService.Cleanup();
await _ioTempService.CleanupAsync(ct);
await _ioTempService.CleanupAsync(TimeSpan.FromHours(1), ct);

Generator

Use session.Generator:

TempDirectorySpec

Describe a folder layout for simulation or zip building:

Storage backends

All I/O goes through IFileSystem. LocalFileSystem and MemoryFileSystem ship in Lyo.IO.FileSystem. Register another IFileSystem via DI for a different backend (SFTP, FTP, S3, Azure Blob). Each backend reports PathStyle (Host on real disk, Posix for in-memory or remote). Service, session, and generator path combine/normalize/jail checks all go through PathHelpers with that style. CopyFrom / MoveFrom / ExtractZipFile may import a host path that sits outside the VFS jail.

LocalFileSystem, the default

Calls System.IO with PathStyle.Host. Picked automatically when no IFileSystem is registered and StorageKind is Local.

// Implicit — no registration needed
services.AddIOTempService();

MemoryFileSystem

Flat path map with a child index and a ReaderWriterLockSlim, using PathStyle.Posix (/ separators, no OS path resolution). No filesystem access; fits Blazor WASM and unit tests. Data lasts for the lifetime of the IFileSystem instance.

// Blazor WASM (Program.cs)
builder.Services.AddMemoryFileSystem();
builder.Services.AddIOTempService();

// Or via options when nothing is registered
services.AddIOTempService(o => o.StorageKind = IOTempStorageKind.Memory);

// xUnit / NUnit — direct construction
var storage = new MemoryFileSystem();
var options = new IOTempSessionOptions { RootDirectory = storage.RootPath };
using var session = new IOTempSession(options, storageProvider: storage);

Write a custom backend

Implement IFileSystem in the package that owns the backend (see SftpFileSystem / FtpFileSystem / S3FileSystem). Register it before AddIOTempService:

services.AddSingleton<IFileSystem>(new FtpFileSystem(ftpClient));
services.AddIOTempService();

FileSystemExtensions covers ReadAllBytes / ReadAllText, TouchFile, WriteAllBytes / WriteAllText / AppendAllText, CopyStreamToFileAsync, and EnsureDirectoryAccessible (used for R/W probing; may be a no-op for in-memory backends).

IOTempServiceOptions

Option Default Description
TempRoot Path.GetTempPath() OS temp root. Parent folder of DirectoryName.
DirectoryName "lyo-io-temp" Folder under TempRoot.
StorageKind Local Local (LocalFileSystem at RootDirectory) or Memory (MemoryFileSystem). Ignored when IFileSystem is already registered.
FileLifetime null Expiry Cleanup() uses when no argument is passed.
MaxFileSizeBytes 1 GB Hard cap per file.
MaxTotalSizeBytes 10 GB Cap on total size under the service directory.
OverflowStrategy ThrowException ThrowException, DeleteOldest, or DeleteLargest.
EnableMetrics true Write metrics through IMetrics.

IOTempSessionOptions

Option Default Description
RootDirectory {TempPath}/lyo-io-temp/{ProcessId} Folder that contains the session directory. A per-process suffix isolates parallel runners by default.
CreateRootDirectoryIfNotExists true If true, a missing RootDirectory is created at construction; if false, a missing root throws.
FileNamingStrategy Guid Guid, Sequential, Timestamp, or RandomChars.
FileExtension .tmp Suffix added to auto-named files.
FilePrefix/Suffix null Optional prefix or suffix on generated file names.
MaxFileSizeBytes 1 GB Hard cap per file.
MaxTotalSizeBytes null Total cap for one session.
OverflowStrategy ThrowException What happens when the total cap is crossed.

IOTempCleanupOptions

Option Default Description
InitialDelay 5 minutes Wait after app startup before the first cleanup run.
Interval 1 hour How often cleanup runs after that first pass.

Dependencies

Generated from ProjectReference / PackageReference (same model as docs/Lyo.ProjectGraph.html).

  • Lyo.Common.Metadata (direct, lyo)
  • Lyo.Exceptions (direct, lyo)
  • Lyo.IO.FileSystem (direct, lyo)
  • Lyo.Metrics (direct, lyo)
  • Microsoft.Extensions.Configuration.Binder 10.0.5 (direct, microsoft)
  • Microsoft.Extensions.Hosting.Abstractions 10.0.5 (direct, microsoft)
  • Lyo.Common.Core (transitive, lyo)
  • Microsoft.Bcl.AsyncInterfaces 10.0.5 (transitive, microsoft, netstandard2.0)
  • Microsoft.Extensions.DependencyInjection.Abstractions 10.0.5 (transitive, microsoft)
  • System.Memory 4.6.3 (transitive, microsoft, netstandard2.0)
  • System.Text.Json 10.0.5 (transitive, microsoft, netstandard2.0)
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (10)

Showing the top 5 NuGet packages that depend on Lyo.IO.Temp:

Package Downloads
Lyo.Web.Components

Blazor components library for the Lyo web UI framework with MudBlazor integration.

Lyo.FileStorage

File storage service interface and base implementation for file operations.

Lyo.Reporting.Postgres

PostgreSQL reporting data layer with EF Core, optional auto-migrations, and report generation orchestration.

Lyo.FileStorage.Web.Components

Reusable Blazor components for file storage: upload/save, path tree browser, DEK/KEK migration and rotation, metadata/expected-storage browser grids.

Lyo.Web.Automation.Playwright

Playwright automation: sessions, tabs, frames, dialogs, keyboard helpers, JSON automation plans, DI registration, and metrics (aligned with Lyo.Web.Automation.Selenium).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 1,016 10/23/2026
2.0.1 560 9/14/2026
2.0.0 654 9/9/2026
1.0.13 622 8/25/2026
1.0.11 737 8/23/2026
1.0.9 807 8/22/2026
1.0.6 1,008 8/20/2026
1.0.4 935 8/20/2026
1.0.3 693 8/19/2026
1.0.2 747 8/19/2026
1.0.1 672 8/18/2026
1.0.0 599 8/16/2026