Beispiel #1
0
        public byte[] ToArray()
        {
            MemoryStream result = new MemoryStream();

            if (_position < _limit)
            {
                result.Write(_buffer, _position, _limit - _position);
                _position = _limit;
            }

            StreamUtility.AppendTo(_stream, result, 0);

            return(result.ToArray());
        }
Beispiel #2
0
        /// <summary>
        /// Побайтовое сравнение двух файлов.
        /// </summary>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <returns>0, если файлы побайтово совпадают.
        /// </returns>
        public static int Compare
        (
            [NotNull] string first,
            [NotNull] string second
        )
        {
            Code.FileExists(first, "first");
            Code.FileExists(second, "second");

            using
            (
                FileStream firstStream = File.OpenRead(first),
                secondStream = File.OpenRead(second)
            )
            {
                return(StreamUtility.CompareTo
                       (
                           firstStream,
                           secondStream
                       ));
            }
        }
        public static byte[] Decompress
        (
            [NotNull] byte[] data
        )
        {
            Sure.NotNull(data, nameof(data));

            MemoryStream memory = new MemoryStream(data);

            using (DeflateStream decompresser = new DeflateStream
                                                (
                       memory,
                       CompressionMode.Decompress
                                                ))
            {
                MemoryStream result = new MemoryStream();
                StreamUtility.AppendTo(decompresser, result, 0);
                decompresser.Dispose();

                return(result.ToArray());
            }
        }
Beispiel #4
0
 /// <summary>
 /// Побайтовое сравнение двух файлов.
 /// </summary>
 /// <param name="first"></param>
 /// <param name="second"></param>
 /// <returns>0, если файлы побайтово совпадают.</returns>
 public static int Compare
 (
     string first,
     string second)
 {
     ArgumentUtility.FileExists
     (
         first,
         "first");
     ArgumentUtility.FileExists
     (
         second,
         "second");
     using (FileStream firstStream = File.OpenRead(first),
            secondStream = File.OpenRead(second))
     {
         return(StreamUtility.Compare
                (
                    firstStream,
                    secondStream));
     }
 }