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
- object
- HttpContent
- HttpContentDecorator
- CompressedContent
- Inherited by
Constructors
CompressedContent(HttpContent, string)
Initializes a new instance of the CompressedContent class.
protected CompressedContent(HttpContent content, string contentEncoding)Parameters
contentHttpContent- The HTTP content to compress.
contentEncodingstring- The encoding type used for compression (e.g., gzip, deflate).
Exceptions
- ArgumentNullException
- Thrown when
contentisnull. - ArgumentException
- Thrown when
contentEncodingisnullor 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
streamStream- The original stream to wrap with a compression stream.
Returns
SerializeToStreamAsync(Stream, TransportContext)
Serializes the HTTP content to a stream as an asynchronous operation.
protected sealed override Task SerializeToStreamAsync(Stream stream, TransportContext context)Parameters
streamStream- The target stream to which the content will be written.
contextTransportContext- 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
lengthlong- The length of the content, if it can be computed.
Returns
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. |
