Akka.Streams.File 1.5.74

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

Akka.Streams.File

NuGet version NuGet downloads

Additional filesystem connectors for Akka.NET Streams: directory change notifications and a sink that rotates between files or application-supplied sinks. The package targets .NET Standard 2.0 and .NET 6. Ordinary file reads and writes are already available through FileIO in Akka.Streams.

dotnet add package Akka.Streams.File

Rotate output files

LogRotatorSink.Create consumes ByteString values and materializes Task<Done>. Its trigger runs for each element. Returning a path opens a new file sink and writes that element into the new file; returning Option<string>.None keeps writing to the current file. Elements received before the first path are discarded. The trigger must return a path for the first element you want to retain.

This complete example writes two elements per file. Choose a writable LOG_DIRECTORY or use the default logs subdirectory. The application creates the directory; the connector does not create missing parent directories.

using Akka.Actor;
using Akka.IO;
using Akka.Streams;
using Akka.Streams.Dsl;
using Akka.Streams.File;
using Akka.Util;

var directory = Environment.GetEnvironmentVariable("LOG_DIRECTORY") ?? Path.Combine(Environment.CurrentDirectory, "logs");
Directory.CreateDirectory(directory);
var run = Guid.NewGuid().ToString("N");
var index = 0;
Option<string> Rotate(ByteString element)
{
    var current = index++;
    return current % 2 == 0
        ? Option<string>.Create(Path.Combine(directory, $"{run}-{current / 2}.log"))
        : Option<string>.None;
}
var system = ActorSystem.Create("rotating-files");
try
{
    await Source.From(new[] { "first\n", "café\n", "last\n" })
        .Select(ByteString.FromString)
        .RunWith(LogRotatorSink.Create(Rotate, FileMode.Create), system.Materializer());
}
finally { await system.Terminate(); }

The default mode is FileMode.OpenOrCreate, which writes from the beginning without truncating an existing longer file. Choose FileMode.Create to truncate or FileMode.Append to append. Bytes are written as supplied; the connector adds no encoding conversion, separators or newline. Rotation is triggered by incoming elements, so a time-based trigger does not rotate an idle stream. It cannot split a single element at a size boundary.

Completion waits for all opened sink materialized tasks. A child failure, cancellation, trigger exception or factory exception fails the outer task; materializer shutdown also fails a pending task. Successful early completion of the current sink cancels upstream and still awaits older sinks. Rotated older sinks can finish independently without stopping the current sink. Failure is not an atomic rollback: earlier writes can remain on disk. Completion/closed handles do not establish durable storage after power loss.

WithSinkFactory<TCriterion, TResult> uses ByteString input and creates Sink<ByteString, Task<TResult>> children. WithTypedSinkFactory<T, TCriterion, TResult> accepts other element types. Their triggers return Option<TCriterion> rotation criteria; the outer materialized value remains Task<Done>. Supply fresh trigger state for each independent stream: the connector retains the supplied delegate rather than cloning its captured mutable state.

Watch a directory

DirectoryChangesSource.Create(path, maxBufferSize) emits (string path, DirectoryChange change) values and materializes NotUsed. The public DirectoryChange enum is in Akka.Streams.File.Impl. The watched directory must already exist; a missing directory throws during stream materialization. This example runs until Ctrl+C and waits for stream termination before terminating the actor system.

using Akka.Actor;
using Akka.Streams;
using Akka.Streams.Dsl;
using Akka.Streams.File;
using Akka.Streams.File.Impl;

var directory = Environment.GetEnvironmentVariable("WATCH_DIRECTORY") ?? Environment.CurrentDirectory;
var system = ActorSystem.Create("directory-watcher");
var stopped = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
ConsoleCancelEventHandler handler = (_, args) => { args.Cancel = true; stopped.TrySetResult(true); };
Console.CancelKeyPress += handler;
try
{
    var (kill, completion) = DirectoryChangesSource.Create(directory, 1024)
        .ViaMaterialized(KillSwitches.Single<(string, DirectoryChange)>(), Keep.Right)
        .ToMaterialized(Sink.ForEach<(string, DirectoryChange)>(change => Console.WriteLine($"{change.Item2}: {change.Item1}")), Keep.Both)
        .Run(system.Materializer());
    await Task.WhenAny(stopped.Task, completion);
    kill.Shutdown();
    await completion;
}
finally
{
    Console.CancelKeyPress -= handler;
    await system.Terminate();
}

The source uses FileSystemWatcher, watches only the immediate directory, and maps create/delete events to Creation/Deletion; writes and renames map to Modification. Rename events report the new full path, with no old-path field. It does not enumerate existing files, recurse into subdirectories or provide a durable event log. Operating systems can duplicate, coalesce or lose notifications; do not depend on exactly one event per operation.

The managed event queue fails with BufferOverflowException when it exceeds maxBufferSize. Backpressure controls emission but cannot pause filesystem changes. The underlying watcher's separate native buffer can overflow too; its Error event is not currently forwarded by this adapter. Use reconciliation or another durable mechanism when missed events are unacceptable. Cancellation stops the source and disposes its owned watcher. There is no checkpoint/replay or automatic watch recovery.

Tests

These connectors use the real temporary filesystem; they do not require Docker, Aspire or cloud credentials. From the repository root, run Linux tests with:

dotnet test src/File/Akka.Streams.File.Tests/Akka.Streams.File.Tests.csproj -c Release --framework net10.0

On Windows, run the portable suite on .NET Framework 4.8:

dotnet test src/File/Akka.Streams.File.Tests/Akka.Streams.File.Tests.csproj -c Release --framework net48 --filter "Platform!=Linux"

Tests retain the original watcher/rotation cases and add exact file-mode/UTF-8 output, exclusive reopening, rename/cancellation, missing directories and controlled child lifecycle failures. Linux additionally observes the target directory's actual inotify watch before cancellation and its removal afterward, using stat and /proc/self/fdinfo. That resource check is explicitly excluded from Windows; ordinary directory deletion alone is not proof of native watch release.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 was computed.  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

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
1.5.74 102 11/13/2026
1.5.59 751 1/27/2026
1.5.57 341 12/23/2025
1.5.40 337 4/18/2025
1.5.37 269 1/23/2025
1.5.33 264 12/26/2024
1.5.28 324 9/9/2024
1.5.18 338 3/29/2024
1.5.15 364 1/11/2024
1.5.8 407 6/30/2023
1.5.7 359 5/31/2023
1.5.0.1 427 3/7/2023
1.5.0 416 3/3/2023
1.4.49 456 3/3/2023
1.0.1-beta4 678 10/21/2022
1.0.1-beta3 330 10/21/2022
1.0.1-beta2 346 7/25/2022
1.0.1-beta1 433 6/8/2022
1.0.0-beta9 422 3/17/2022
1.0.0-beta8 379 12/21/2021
Loading failed

* Bump the minimum Akka.NET dependency to [1.5.74](https://github.com/akkadotnet/akka.net/releases/tag/1.5.74), with aligned Streams and TestKit dependencies.
* Include an individual README in each of the twelve connector packages, with usage, ownership, delivery semantics, limitations and linked NuGet version/download badges. Expand the repository README and documentation navigation.
* Update compatible Azure, AWS, AMQP and SignalR dependencies. Package READMEs document remaining SDK support and version limitations.
* Azure Service Bus JSON sources await successful message completion before emitting values and propagate settlement failures.
* Fix SQS batch-response correlation when response entries arrive in a different order.
* Improve SNS and Kinesis completion, cancellation and failure handling.
* Remove blocking SignalR send waits while preserving sequential delivery and existing materialized values.
* Propagate AMQP conversion and connection failures through the materialized completion task.
* Correct CSV parsing across split CRLF/escape sequences and XML parser empty-element/document completion, including reader and feeder cleanup.
* Improve rotating-file sink cleanup on completion and failures.
* Add required service integration, package/API, unchanged-consumer and packaged-example validation. Harden Event Hubs startup and Service Bus polling tests.
* Replace legacy FluentAssertions usages with xUnit assertions, retaining their payload, ordering, exception and deadline checks.
* Mark the historical `Akka.Streams.Channels`, `Akka.Streams.Azure.EventHub.V5` and `Akka.Streams.SignalR.AspNetCore` packages as Legacy on NuGet. See the [migration guide](https://alpakka.getakka.net/documentation/LegacyPackages.html) for their maintained replacements and compatibility requirements.

**Upstream compatibility:** Alpakka retains its public APIs and library targets. Raising the Akka.NET minimum from 1.5.60 inherits upstream binary changes: the old `RetrySupport.Retry` overload with an `int randomFactor` is replaced by a `double` overload, and `ISourceQueue<T>` requires `OfferAsync(T, CancellationToken)`. Applications using that old compiled overload or custom queue implementations need to update and rebuild against the new dependencies.