Read() public method

Read data from the stream.

If you wish to use the ZlibStream to compress data while reading, you can create a ZlibStream with CompressionMode.Compress, providing an uncompressed data stream. Then call Read() on that ZlibStream, and the data read will be compressed. If you wish to use the ZlibStream to decompress data while reading, you can create a ZlibStream with CompressionMode.Decompress, providing a readable compressed data stream. Then call Read() on that ZlibStream, and the data will be decompressed as it is read.

A ZlibStream can be used for Read() or Write(), but not both.

public Read ( byte buffer, int offset, int count ) : int
buffer byte The buffer into which the read data should be placed.
offset int the offset within that data array to put the first byte read.
count int the number of bytes to read.
return int
コード例 #1
0
ファイル: ZLibStream.cs プロジェクト: FlatlinerDOA/FlatBeats
        /// <summary>
        /// Uncompress a byte array into a single string.
        /// </summary>
        /// <seealso cref="ZlibStream.CompressString(String)"/>
        /// <param name="compressed">
        /// A buffer containing ZLIB-compressed data.
        /// </param>
        public static String UncompressString(byte[] compressed)
        {
            // workitem 8460
            byte[] working  = new byte[1024];
            var    encoding = System.Text.Encoding.UTF8;

            using (var output = new MemoryStream())
            {
                using (var input = new MemoryStream(compressed))
                {
                    using (Stream decompressor = new ZlibStream(input))
                    {
                        int n;
                        while ((n = decompressor.Read(working, 0, working.Length)) != 0)
                        {
                            output.Write(working, 0, n);
                        }
                    }
                    // reset to allow read from start
                    output.Seek(0, SeekOrigin.Begin);
                    var sr = new StreamReader(output, encoding);
                    return(sr.ReadToEnd());
                }
            }
        }
コード例 #2
0
ファイル: ZLibStream.cs プロジェクト: FlatlinerDOA/FlatBeats
 /// <summary>
 /// Uncompress a byte array into a byte array.
 /// </summary>
 /// <seealso cref="ZlibStream.CompressBuffer(byte[])"/>
 /// <seealso cref="ZlibStream.UncompressString(byte[])"/>
 /// <param name="compressed">
 /// A buffer containing ZLIB-compressed data.
 /// </param>
 public static byte[] UncompressBuffer(byte[] compressed)
 {
     // workitem 8460
     byte[] working = new byte[1024];
     using (var output = new MemoryStream())
     {
         using (var input = new MemoryStream(compressed))
         {
             using (Stream decompressor = new ZlibStream(input))
             {
                 int n;
                 while ((n = decompressor.Read(working, 0, working.Length)) != 0)
                 {
                     output.Write(working, 0, n);
                 }
             }
             return(output.ToArray());
         }
     }
 }
コード例 #3
0
 /// <summary>
 /// Uncompress a byte array into a single string.
 /// </summary>
 /// <seealso cref="ZlibStream.CompressString(String)"/>
 /// <param name="compressed">
 /// A buffer containing ZLIB-compressed data.  
 /// </param>
 public static String UncompressString(byte[] compressed)
 {
     // workitem 8460
     byte[] working = new byte[1024];
     var encoding = System.Text.Encoding.UTF8;
     using (var output = new MemoryStream())
     {
         using (var input = new MemoryStream(compressed))
         {
             using (Stream decompressor = new ZlibStream(input))
             {
                 int n;
                 while ((n = decompressor.Read(working, 0, working.Length)) != 0)
                 {
                     output.Write(working, 0, n);
                 }
             }
             // reset to allow read from start
             output.Seek(0, SeekOrigin.Begin);
             var sr = new StreamReader(output, encoding);
             return sr.ReadToEnd();
         }
     }
 }
コード例 #4
0
 /// <summary>
 /// Uncompress a byte array into a byte array.
 /// </summary>
 /// <seealso cref="ZlibStream.CompressBuffer(byte[])"/>
 /// <seealso cref="ZlibStream.UncompressString(byte[])"/>
 /// <param name="compressed">
 /// A buffer containing ZLIB-compressed data.  
 /// </param>
 public static byte[] UncompressBuffer(byte[] compressed)
 {
     // workitem 8460
     byte[] working = new byte[1024];
     using (var output = new MemoryStream())
     {
         using (var input = new MemoryStream(compressed))
         {
             using (Stream decompressor = new ZlibStream(input))
             {
                 int n;
                 while ((n = decompressor.Read(working, 0, working.Length)) != 0)
                 {
                     output.Write(working, 0, n);
                 }
             }
             return output.ToArray();
         }
     }
 }