5 public sealed
class StreamWrapper(Stream Wrapped, IDisposable? AdditionalDisposable) : Stream
7 private readonly Stream wrapped = Wrapped;
8 private IDisposable? additionalDisposable = AdditionalDisposable;
10 public event EventHandler? Disposed;
12 public StreamWrapper(Stream Wrapped) : this(Wrapped, null)
16 public override long Position
18 get => this.wrapped.Position;
19 set => this.wrapped.Position = value;
22 public override long Length => this.wrapped.Length;
23 public override bool CanRead => this.wrapped.CanRead;
24 public override bool CanSeek => this.wrapped.CanSeek;
25 public override bool CanWrite => this.wrapped.CanWrite;
27 public override void Flush() => this.wrapped.Flush();
28 public override int Read(
byte[] Buffer,
int Offset,
int Count) => this.wrapped.Read(Buffer, Offset, Count);
29 public override long Seek(
long Offset, SeekOrigin Origin) => this.wrapped.Seek(Offset, Origin);
30 public override void SetLength(
long Value) => this.wrapped.SetLength(Value);
31 public override void Write(
byte[] Buffer,
int Offset,
int Count) => this.wrapped.Write(Buffer, Offset, Count);
33 protected override void Dispose(
bool Disposing)
35 this.wrapped.Dispose();
37 Disposed.Raise(
this, EventArgs.Empty);
39 this.additionalDisposable?.Dispose();
40 this.additionalDisposable =
null;
42 base.Dispose(Disposing);
45 public static async Task<Stream?> GetStreamAsync(Uri uri, HttpClient client, CancellationToken cancellationToken)
47 HttpResponseMessage Response = await client.GetAsync(uri, cancellationToken).ConfigureAwait(
false);
49 if (!Response.IsSuccessStatusCode)
56 return new StreamWrapper(await Response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(
false), Response);