This commit is contained in:
2026-06-15 18:18:16 +08:00
parent 97c9fba14e
commit 2b9f134e5f
4164 changed files with 386922 additions and 79 deletions

View File

@@ -0,0 +1,50 @@
using Best.HTTP.Shared.PlatformSupport.Network.Tcp;
namespace Best.HTTP.Shared.Streams
{
/// <summary>
/// A PeekableStream implementation that also implements the <see cref="IPeekableContentProvider"/> interface too.
/// </summary>
public abstract class PeekableContentProviderStream : PeekableStream, IPeekableContentProvider
{
public PeekableContentProviderStream Peekable => this;
public IContentConsumer Consumer { get; private set; }
public void SetTwoWayBinding(IContentConsumer consumer)
{
this.Consumer = consumer;
this.Consumer?.SetBinding(this);
}
/// <summary>
/// This will set Consumer to null.
/// </summary>
public void Unbind()
{
this.Consumer?.UnsetBinding();
this.Consumer = null;
}
/// <summary>
/// Set Consumer to null if the current one is the one passed in the parameter.
/// </summary>
public void UnbindIf(IContentConsumer consumer)
{
if (consumer == null || consumer == this.Consumer)
{
this.Consumer?.UnsetBinding();
this.Consumer = null;
}
}
public void SwitchIf(IContentConsumer from, IContentConsumer to)
{
if (from == null || from == this.Consumer)
{
this.Consumer?.UnsetBinding();
SetTwoWayBinding(to);
}
}
}
}