Write() public method

When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
public Write ( byte buffer, int offset, int count ) : void
buffer byte An array of bytes. This method copies bytes from to the current stream.
offset int The zero-based byte offset in at which to begin copying bytes to the current stream.
count int The number of bytes to be written to the current stream.
return void
Exemplo n.º 1
0
        public void Save(System.IO.Stream stream)
        {
            MemoryStream memoryStream = new MemoryStream();
            var          writer       = new System.IO.BinaryWriter(memoryStream);

            writer.Write(dict.Count);
            foreach (KeyValuePair <string, LZ4Entry> pair in dict)
            {
                writer.Write(pair.Key);
                writer.Write(pair.Value.bytes.Length);
                writer.Write(pair.Value.bytes);
            }
            using (LZ4Stream lz4Stream = new LZ4Stream(stream, CompressionMode.Compress, LZ4StreamFlags.HighCompression))
            {
                lz4Stream.Write(memoryStream.ToArray(), 0, (int)memoryStream.Length);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Compresses a byte array.
 /// </summary>
 /// <param name="input">Uncompressed data.</param>
 /// <returns>Compressed data.</returns>
 public static byte[] Compress(byte[] input)
 {
     MemoryStream memstream = new MemoryStream();
     LZ4Stream lzstream = new LZ4Stream(memstream, LZ4StreamMode.Compress);
     lzstream.Write(input, 0, input.Length);
     lzstream.Close();
     byte[] finaldata = memstream.ToArray();
     memstream.Close();
     return finaldata;
 }