[]
Compresses data into .NET Streams.
public class C1ZStreamWriter : Stream, IDisposable, IAsyncDisposable
To compress data into a stream, create a C1ZStreamWriter object passing the stream to the C1ZStreamWriter constructor.
Then write the data into the C1ZStreamWriter using the Write(byte[], int, int) method, or create a StreamWriter on the C1ZStreamWriter. The second option is indicated when you want to write formatted data.
When you are done writing the data, call the Close() method to flush the data and close the underlying stream.
The code below compresses a string into a memory stream:
public byte[] CompressString(string str)
{
// open memory stream
var ms = new MemoryStream();
// attach compressor stream to memory stream
var sw = new C1ZStreamWriter(ms);
// write data into compressor stream
var writer = new StreamWriter(sw);
writer.Write(str);
// flush any pending data
writer.Flush();
// return the memory buffer
return ms.ToArray();
}
Name | Description |
---|---|
C1ZStreamWriter(Stream) | Initializes a new instance of the C1ZStreamWriter class. |
C1ZStreamWriter(Stream, CompressionLevelEnum) | Initializes a new instance of the C1ZStreamWriter class. |
C1ZStreamWriter(Stream, CompressionLevelEnum, bool) | Initializes a new instance of the C1ZStreamWriter class. |
C1ZStreamWriter(Stream, CompressionLevelEnum, bool, bool) | Initializes a new instance of the C1ZStreamWriter class. |
C1ZStreamWriter(Stream, bool) | Initializes a new instance of the C1ZStreamWriter class. |
C1ZStreamWriter(Stream, bool, bool) | Initializes a new instance of the C1ZStreamWriter class. |
Name | Description |
---|---|
BaseStream | Gets the underlying stream that receives the compressed data. |
CanRead | Always returns False. |
CanSeek | Always returns False. |
CanWrite | Always returns True. |
Checksum | Gets the checksum value used to check the integrity of the stream. |
Length | Returns the length of the underlying stream, in bytes. |
OwnsBaseStream | Gets or sets whether calling the Close() method will also close the underlying stream (see BaseStream). |
Position | Gets the position within the stream (read-only). |
SizeCompressed | Gets the number of bytes in the stream (compressed bytes). |
SizeCompressedLong | Gets the number of bytes in the stream (compressed bytes). |
SizeUncompressed | Gets the number of bytes that were compressed into the stream (uncompressed bytes). |
SizeUncompressedLong | Gets the number of bytes that were compressed into the stream (uncompressed bytes). |
ZStream | Gets the ZStream instance wrapped by this C1ZStreamWriter. |
Name | Description |
---|---|
Close() | Closes the current stream compressor and flushed any pending data into the base stream. If the OwnsBaseStream property is set to True (the default value), then this method also closes the base stream and releases any resources (such as sockets and file handles) associated with it. |
Flush() | Clears all buffers for this stream and causes any buffered data to be written to the underlying stream. |
Read(byte[], int, int) | Not supported. |
Seek(long, SeekOrigin) | Not supported. |
SetLength(long) | Not supported. |
Write(byte[], int, int) | Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. |
WriteByte(byte) | Writes a byte to the current position in the stream and advances the position within the stream by one byte. |