using Best.HTTP.Shared.PlatformSupport.Network.Tcp;
namespace Best.HTTP.Shared.Streams
{
///
/// A PeekableStream implementation that also implements the interface too.
///
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);
}
///
/// This will set Consumer to null.
///
public void Unbind()
{
this.Consumer?.UnsetBinding();
this.Consumer = null;
}
///
/// Set Consumer to null if the current one is the one passed in the parameter.
///
public void UnbindIf(IContentConsumer consumer)
{
if (consumer == null || consumer == this.Consumer)
{
this.Consumer?.UnsetBinding();
this.Consumer = null;
}
}
}
}