Ejemplo n.º 1
0
 /// <summary>
 /// Reads a block from the underlying stream and compresses it
 /// </summary>
 /// <returns>
 /// True if data was read and compressed
 /// False if the end of the underlying stream was reached
 /// </returns>
 private Boolean ReadAndCompress()
 {
     this.streamOffset = this.streamLength = 0;
      // read the uncompressed block into the read buffer
      var decoded = ReadBlock(this.readBuffer, this.readBuffer.Length);
      if (decoded > 0)
      {
     // compress the block into the stream buffer,
     // leaving room for the header
     var encoded = Encode(
        this.readBuffer,
        0,
        decoded,
        this.streamBuffer,
        BlockHeader.Size
     );
     // copy the length header into the stream buffer
     var header = new BlockHeader()
     {
        EncodedLength = encoded,
        DecodedLength = decoded
     };
     this.streamLength += header.Encode(this.streamBuffer);
     this.streamLength += encoded;
     return true;
      }
      return false;
 }