# C1.Zip.C1ZStreamWriter

## Content

<div class="doc-site-dotnet-api-container">



  <h1 id="C1_Zip_C1ZStreamWriter" data-uid="C1.Zip.C1ZStreamWriter" class="text-break">C1ZStreamWriter Class
</h1>
  <div class="markdown level0 summary"><p>Compresses data into .NET Streams.</p>
</div>
  <div class="markdown level0 conceptual"></div>
  <div class="inheritance">
    <h5>Inheritance</h5>
    <div class="level0"><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></div>
    <div class="level1"><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.marshalbyrefobject">MarshalByRefObject</a></div>
    <div class="level2"><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.io.stream">Stream</a></div>
    <div class="level3"><span class="xref">C1ZStreamWriter</span></div>
  </div>
  <div class="implements">
    <h5>Implements</h5>
    <div><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.idisposable">IDisposable</a></div>
  </div>
  <h6><strong>Namespace</strong>: <a class="xref" href="C1.Zip.html">C1.Zip</a></h6>
  <h6><strong>Assembly</strong>: C1.Zip.dll</h6>
  <h5 id="C1_Zip_C1ZStreamWriter_syntax">Syntax</h5>
  <div class="codewrapper">
    <pre><code class="lang-csharp hljs">public class C1ZStreamWriter : Stream, IDisposable</code></pre>
  </div>
  <div class="codewrapper">
    <pre><code class="lang-vbnet hljs">Public Class C1ZStreamWriter
    Inherits Stream
    Implements IDisposable</code></pre>
  </div>
  <h5 id="C1_Zip_C1ZStreamWriter_remarks"><strong>Remarks</strong></h5>
  <div class="markdown level0 remarks"><p>To compress data into a stream, create a <a class="xref" href="C1.Zip.C1ZStreamWriter.html">C1ZStreamWriter</a> object 
passing the stream to the <a class="xref" href="C1.Zip.C1ZStreamWriter.html">C1ZStreamWriter</a> constructor.</p>
<p>Then write the data into the <a class="xref" href="C1.Zip.C1ZStreamWriter.html">C1ZStreamWriter</a> using the <a class="xref" href="C1.Zip.C1ZStreamWriter.Write.html#C1_Zip_C1ZStreamWriter_Write_System_Byte___System_Int32_System_Int32_">Write(byte[], int, int)</a>
method, or create a <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.io.streamwriter">StreamWriter</a> on the <a class="xref" href="C1.Zip.C1ZStreamWriter.html">C1ZStreamWriter</a>. 
The second option is indicated when you want to write formatted data.</p>
<p>When you are done writing the data, call the <a class="xref" href="C1.Zip.C1ZStreamWriter.Close.html#C1_Zip_C1ZStreamWriter_Close">Close()</a> method to
flush the data and close the underlying stream.</p>
</div>
  <h5 id="C1_Zip_C1ZStreamWriter_examples"><strong>Examples</strong></h5>
  <p>The code below compresses a string into a memory stream:</p>
<pre><code class="lang-csharp">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();
}</code></pre>

  <h3 id="constructors">Constructors
</h3>
  <table class="table table-bordered table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter__ctor_System_IO_Stream_" data-uid="C1.Zip.C1ZStreamWriter.#ctor(System.IO.Stream)">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.-ctor.html#C1_Zip_C1ZStreamWriter__ctor_System_IO_Stream_">C1ZStreamWriter(Stream)</a>
        </td>
        <td class="markdown level1 summary"><p>Initializes a new instance of the <a class="xref" href="C1.Zip.C1ZStreamWriter.html">C1ZStreamWriter</a> class.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter__ctor_System_IO_Stream_C1_Zip_CompressionLevelEnum_" data-uid="C1.Zip.C1ZStreamWriter.#ctor(System.IO.Stream,C1.Zip.CompressionLevelEnum)">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.-ctor.html#C1_Zip_C1ZStreamWriter__ctor_System_IO_Stream_C1_Zip_CompressionLevelEnum_">C1ZStreamWriter(Stream, CompressionLevelEnum)</a>
        </td>
        <td class="markdown level1 summary"><p>Initializes a new instance of the <a class="xref" href="C1.Zip.C1ZStreamWriter.html">C1ZStreamWriter</a> class.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter__ctor_System_IO_Stream_C1_Zip_CompressionLevelEnum_System_Boolean_" data-uid="C1.Zip.C1ZStreamWriter.#ctor(System.IO.Stream,C1.Zip.CompressionLevelEnum,System.Boolean)">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.-ctor.html#C1_Zip_C1ZStreamWriter__ctor_System_IO_Stream_C1_Zip_CompressionLevelEnum_System_Boolean_">C1ZStreamWriter(Stream, CompressionLevelEnum, bool)</a>
        </td>
        <td class="markdown level1 summary"><p>Initializes a new instance of the <a class="xref" href="C1.Zip.C1ZStreamWriter.html">C1ZStreamWriter</a> class.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter__ctor_System_IO_Stream_C1_Zip_CompressionLevelEnum_System_Boolean_System_Boolean_" data-uid="C1.Zip.C1ZStreamWriter.#ctor(System.IO.Stream,C1.Zip.CompressionLevelEnum,System.Boolean,System.Boolean)">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.-ctor.html#C1_Zip_C1ZStreamWriter__ctor_System_IO_Stream_C1_Zip_CompressionLevelEnum_System_Boolean_System_Boolean_">C1ZStreamWriter(Stream, CompressionLevelEnum, bool, bool)</a>
        </td>
        <td class="markdown level1 summary"><p>Initializes a new instance of the <a class="xref" href="C1.Zip.C1ZStreamWriter.html">C1ZStreamWriter</a> class.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter__ctor_System_IO_Stream_System_Boolean_" data-uid="C1.Zip.C1ZStreamWriter.#ctor(System.IO.Stream,System.Boolean)">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.-ctor.html#C1_Zip_C1ZStreamWriter__ctor_System_IO_Stream_System_Boolean_">C1ZStreamWriter(Stream, bool)</a>
        </td>
        <td class="markdown level1 summary"><p>Initializes a new instance of the <a class="xref" href="C1.Zip.C1ZStreamWriter.html">C1ZStreamWriter</a> class.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter__ctor_System_IO_Stream_System_Boolean_System_Boolean_" data-uid="C1.Zip.C1ZStreamWriter.#ctor(System.IO.Stream,System.Boolean,System.Boolean)">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.-ctor.html#C1_Zip_C1ZStreamWriter__ctor_System_IO_Stream_System_Boolean_System_Boolean_">C1ZStreamWriter(Stream, bool, bool)</a>
        </td>
        <td class="markdown level1 summary"><p>Initializes a new instance of the <a class="xref" href="C1.Zip.C1ZStreamWriter.html">C1ZStreamWriter</a> class.</p>
</td>
      </tr>
    </tbody>
  </table>
  <h3 id="properties">Properties
</h3>
  <table class="table table-bordered table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_BaseStream" data-uid="C1.Zip.C1ZStreamWriter.BaseStream">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.BaseStream.html#C1_Zip_C1ZStreamWriter_BaseStream">BaseStream</a>
        </td>
        <td class="markdown level1 summary"><p>Gets the underlying stream that receives the compressed data.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_CanRead" data-uid="C1.Zip.C1ZStreamWriter.CanRead">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.CanRead.html#C1_Zip_C1ZStreamWriter_CanRead">CanRead</a>
        </td>
        <td class="markdown level1 summary"><p>Always returns False.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_CanSeek" data-uid="C1.Zip.C1ZStreamWriter.CanSeek">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.CanSeek.html#C1_Zip_C1ZStreamWriter_CanSeek">CanSeek</a>
        </td>
        <td class="markdown level1 summary"><p>Always returns False.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_CanWrite" data-uid="C1.Zip.C1ZStreamWriter.CanWrite">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.CanWrite.html#C1_Zip_C1ZStreamWriter_CanWrite">CanWrite</a>
        </td>
        <td class="markdown level1 summary"><p>Always returns True.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_Checksum" data-uid="C1.Zip.C1ZStreamWriter.Checksum">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.Checksum.html#C1_Zip_C1ZStreamWriter_Checksum">Checksum</a>
        </td>
        <td class="markdown level1 summary"><p>Gets the checksum value used to check the integrity of the stream.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_Length" data-uid="C1.Zip.C1ZStreamWriter.Length">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.Length.html#C1_Zip_C1ZStreamWriter_Length">Length</a>
        </td>
        <td class="markdown level1 summary"><p>Returns the length of the underlying stream, in bytes.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_OwnsBaseStream" data-uid="C1.Zip.C1ZStreamWriter.OwnsBaseStream">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.OwnsBaseStream.html#C1_Zip_C1ZStreamWriter_OwnsBaseStream">OwnsBaseStream</a>
        </td>
        <td class="markdown level1 summary"><p>Gets or sets whether calling the <a class="xref" href="C1.Zip.C1ZStreamWriter.Close.html#C1_Zip_C1ZStreamWriter_Close">Close()</a> method will also close the underlying stream (see <a class="xref" href="C1.Zip.C1ZStreamWriter.BaseStream.html#C1_Zip_C1ZStreamWriter_BaseStream">BaseStream</a>).</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_Position" data-uid="C1.Zip.C1ZStreamWriter.Position">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.Position.html#C1_Zip_C1ZStreamWriter_Position">Position</a>
        </td>
        <td class="markdown level1 summary"><p>Gets the position within the stream (read-only).</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_SizeCompressed" data-uid="C1.Zip.C1ZStreamWriter.SizeCompressed">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.SizeCompressed.html#C1_Zip_C1ZStreamWriter_SizeCompressed">SizeCompressed</a>
        </td>
        <td class="markdown level1 summary"><p>Gets the number of bytes in the stream (compressed bytes).</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_SizeCompressedLong" data-uid="C1.Zip.C1ZStreamWriter.SizeCompressedLong">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.SizeCompressedLong.html#C1_Zip_C1ZStreamWriter_SizeCompressedLong">SizeCompressedLong</a>
        </td>
        <td class="markdown level1 summary"><p>Gets the number of bytes in the stream (compressed bytes).</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_SizeUncompressed" data-uid="C1.Zip.C1ZStreamWriter.SizeUncompressed">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.SizeUncompressed.html#C1_Zip_C1ZStreamWriter_SizeUncompressed">SizeUncompressed</a>
        </td>
        <td class="markdown level1 summary"><p>Gets the number of bytes that were compressed into the stream (uncompressed bytes).</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_SizeUncompressedLong" data-uid="C1.Zip.C1ZStreamWriter.SizeUncompressedLong">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.SizeUncompressedLong.html#C1_Zip_C1ZStreamWriter_SizeUncompressedLong">SizeUncompressedLong</a>
        </td>
        <td class="markdown level1 summary"><p>Gets the number of bytes that were compressed into the stream (uncompressed bytes).</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_ZStream" data-uid="C1.Zip.C1ZStreamWriter.ZStream">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.ZStream.html#C1_Zip_C1ZStreamWriter_ZStream">ZStream</a>
        </td>
        <td class="markdown level1 summary"><p>Gets the ZStream instance wrapped by this <a class="xref" href="C1.Zip.C1ZStreamWriter.html">C1ZStreamWriter</a>.</p>
</td>
      </tr>
    </tbody>
  </table>
  <h3 id="methods">Methods
</h3>
  <table class="table table-bordered table-condensed">
    <thead>
      <tr>
        <th>Name</th>
        <th>Description</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_Close" data-uid="C1.Zip.C1ZStreamWriter.Close">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.Close.html#C1_Zip_C1ZStreamWriter_Close">Close()</a>
        </td>
        <td class="markdown level1 summary"><p>Closes the current stream compressor and flushed any pending data into the base stream.</p>
<p>If the <a class="xref" href="C1.Zip.C1ZStreamWriter.OwnsBaseStream.html#C1_Zip_C1ZStreamWriter_OwnsBaseStream">OwnsBaseStream</a> 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.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_Flush" data-uid="C1.Zip.C1ZStreamWriter.Flush">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.Flush.html#C1_Zip_C1ZStreamWriter_Flush">Flush()</a>
        </td>
        <td class="markdown level1 summary"><p>Clears all buffers for this stream and causes any buffered data to be written to the underlying
stream.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_Read_System_Byte___System_Int32_System_Int32_" data-uid="C1.Zip.C1ZStreamWriter.Read(System.Byte[],System.Int32,System.Int32)">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.Read.html#C1_Zip_C1ZStreamWriter_Read_System_Byte___System_Int32_System_Int32_">Read(byte[], int, int)</a>
        </td>
        <td class="markdown level1 summary"><p>Not supported.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_Seek_System_Int64_System_IO_SeekOrigin_" data-uid="C1.Zip.C1ZStreamWriter.Seek(System.Int64,System.IO.SeekOrigin)">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.Seek.html#C1_Zip_C1ZStreamWriter_Seek_System_Int64_System_IO_SeekOrigin_">Seek(long, SeekOrigin)</a>
        </td>
        <td class="markdown level1 summary"><p>Not supported.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_SetLength_System_Int64_" data-uid="C1.Zip.C1ZStreamWriter.SetLength(System.Int64)">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.SetLength.html#C1_Zip_C1ZStreamWriter_SetLength_System_Int64_">SetLength(long)</a>
        </td>
        <td class="markdown level1 summary"><p>Not supported.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_Write_System_Byte___System_Int32_System_Int32_" data-uid="C1.Zip.C1ZStreamWriter.Write(System.Byte[],System.Int32,System.Int32)">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.Write.html#C1_Zip_C1ZStreamWriter_Write_System_Byte___System_Int32_System_Int32_">Write(byte[], int, int)</a>
        </td>
        <td class="markdown level1 summary"><p>Writes a sequence of bytes to the current stream and advances the current
position within this stream by the number of bytes written.</p>
</td>
      </tr>
      <tr>
        <td id="C1_Zip_C1ZStreamWriter_WriteByte_System_Byte_" data-uid="C1.Zip.C1ZStreamWriter.WriteByte(System.Byte)">
          <a class="xref" href="C1.Zip.C1ZStreamWriter.WriteByte.html#C1_Zip_C1ZStreamWriter_WriteByte_System_Byte_">WriteByte(byte)</a>
        </td>
        <td class="markdown level1 summary"><p>Writes a byte to the current position in the stream and advances the position within the stream by one byte.</p>
</td>
      </tr>
    </tbody>
  </table>

</div>
