You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature] Add properties to track bytes compressed/decompressed to CompressionStream/DecompressionStream #59
It is sometime useful to know the number of bytes compressed by a CompressionStream and decompressed by a DecompressionStream. There is currently no easy way to determine this. Therefore, it would be great if properties were to be added to the CompressionStream and DecompressionStream classes that count the number of bytes compressed/decompressed.
In .NET the standard approach to add new functionality to a Stream is to wrap it. This will work with any streams, including the built-in DeflateStream and BrotliStream. You can simply override Read/Write and count the bytes.
In .NET the standard approach to add new functionality to a Stream is to wrap it.
That's what I meant when I said there was no "easy way". .NET doesn't provide any such wrapper in the standard library, which means we each need to write our own wrapper to count the bytes.
Note that Utf8JsonWriter has BytesWritten and BytesPending properties for this purpose.
But yes, I recognize that other compression stream types in the .NET standard library have the same problem.
Activity
oleg-st commentedon Sep 24, 2025
In .NET the standard approach to add new functionality to a
Streamis to wrap it. This will work with any streams, including the built-inDeflateStreamandBrotliStream. You can simply override Read/Write and count the bytes.bill-poole commentedon Sep 24, 2025
That's what I meant when I said there was no "easy way". .NET doesn't provide any such wrapper in the standard library, which means we each need to write our own wrapper to count the bytes.
Note that
Utf8JsonWriterhasBytesWrittenandBytesPendingproperties for this purpose.But yes, I recognize that other compression stream types in the .NET standard library have the same problem.