Duplicati.StreamUtil
1.0.5
dotnet add package Duplicati.StreamUtil --version 1.0.5
NuGet\Install-Package Duplicati.StreamUtil -Version 1.0.5
<PackageReference Include="Duplicati.StreamUtil" Version="1.0.5" />
<PackageVersion Include="Duplicati.StreamUtil" Version="1.0.5" />
<PackageReference Include="Duplicati.StreamUtil" />
paket add Duplicati.StreamUtil --version 1.0.5
#r "nuget: Duplicati.StreamUtil, 1.0.5"
#:package Duplicati.StreamUtil@1.0.5
#addin nuget:?package=Duplicati.StreamUtil&version=1.0.5
#tool nuget:?package=Duplicati.StreamUtil&version=1.0.5
Stream utility
Stream wrappers that add functionality to the .NET base streams.
Helpers: WrappingStream and WrappingAsyncStream
It contains the WrappingStream abstract class that simplifies wrapping another Stream by delegating all calls to that underlying stream. The WrappingAsyncStream is similar by changes the required implementation to be the async read/write methods and lets the synchronous methods use the async implementation by default.
Timeout support
On top of these helpers, the TimeoutObservingStream adds the missing timeout functionality to streams, such that streams operations can actually be cancelled via the CancellationToken as well as the timeout property, which is not fully supported for ordinary streams. Notably, HttpClient does not support timeout on the streams and the System.IO.Stream.ReadAsync / System.IO.Stream.WriteAsync only checks the cancellation token on entry and ignores it during and after the operation.
This is problematic in situations where the expected transfer time is unknown, such as uploading or downloading large files. Because the network and remote site has unknown bandwidth requirements, it is not possible to determine in advance how long a timeout to use for the entire operation. One approach to this problem is to ensure that some progress is made, meaning that each operation has to complete within a set time, and if it does, it means that progress is made. Only in the event where progress stops or slows beyound a certain threshold is the connection stopped.
The ReadTimeout and WriteTimeout can be set during use, but is only read when entering a read or write operation. In other words: setting timeout while a read/write operation is active will take effect on the next read/write call.
Throttle (aka rate-limit, aka bandwidth control)
The ThrottleEnabledStream allows the caller to throttle (aka rate-limit) the read and/or write speed by inserting small pauses, either with Thread.Sleep() or await Task.Delay() for sync/async respectively. A throttle value of zero will disable the throttle.
If needed, the ThrottleManager can be shared among multiple ThrottleEnabledStream instances allowing a subset of streams to share a set bandwidth limit.
Composable stream
The LambdaInterceptStream is not implemented with performance in mind, but is useful for implementing various test or logging setups by wrapping a stream an allowing weaved methods before and after calls.
Example use
var fileStream = File.Open(...);
var timeoutStream = new TimeoutObservingStream(fileStream) {
ReadTimeout = (int)TimeSpan.FromSeconds(3).TotalMilliSeconds
};
var ms = new MemoryStream();
var cts = new CancellationTokenSource();
// Any
await timeoutStream.CopyAsync(ms, cts.Token);
| Product | Versions 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. 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. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Duplicati.StreamUtil:
| Repository | Stars |
|---|---|
|
duplicati/duplicati
Store securely encrypted backups in the cloud!
|
Fixed issue with dispose not being propagated. More smooth throttling.