CompressedContent Class

Namespace
Kampute.HttpClient.Content.Compression.Abstracts
Assembly
  • Kampute.HttpClient.dll

Definition

Provides a base class for creating HTTP content based on compression.
public abstract class CompressedContent : HttpContentDecorator
Inheritance
Inherited by

Constructors

CompressedContent(HttpContent, string)

Initializes a new instance of the CompressedContent class.
protected CompressedContent(HttpContent content, string contentEncoding)

Parameters

content HttpContent
The HTTP content to compress.
contentEncoding string
The encoding type used for compression (e.g., gzip, deflate).

Exceptions

ArgumentNullException
Thrown when content is null.
ArgumentException
Thrown when contentEncoding is null or empty.

Methods

CompressStream(Stream)

When overridden in a derived class, returns a stream that wraps the provided base stream with a compression layer.
protected abstract Stream CompressStream(Stream stream)

Parameters

stream Stream
The original stream to wrap with a compression stream.

Returns

Stream
A Stream that compresses the content as it is written to the stream.

SerializeToStreamAsync(Stream, TransportContext)

Serializes the HTTP content to a stream as an asynchronous operation.
protected sealed override Task SerializeToStreamAsync(Stream stream, TransportContext context)

Parameters

stream Stream
The target stream to which the content will be written.
context TransportContext
Information about the transport (e.g., channel binding token).

Returns

Task
The task object representing the asynchronous operation.

TryComputeLength(out long)

Tries to compute the length of the compressed content.
protected sealed override bool TryComputeLength(out long length)

Parameters

length long
The length of the content, if it can be computed.

Returns

bool
false as the compressed content length is not predictable before compression.

Extension Methods

AsDeflate(this HttpContent, CompressionLevel)Compresses the HttpContent using the Deflate compression algorithm.
AsGzip(this HttpContent, CompressionLevel)Compresses the HttpContent using the GZIP compression algorithm.
FindCharacterEncoding(this HttpContent)Attempts to find the character encoding from the HttpContent headers.
IsReusable(this HttpContent)Determines whether the HttpContent instance can be reused.