Ejemplo n.º 1
0
 public static uint GetCrc(string path)
 {
     BestHTTP.Decompression.Crc.CRC32 checker = new BestHTTP.Decompression.Crc.CRC32();
     using (FileStream stream = File.OpenRead(path))
     {
         return((uint)checker.GetCrc32(stream));
     }
 }
Ejemplo n.º 2
0
    public static bool CheckCrc(string path, uint crc)
    {
        if (crc == 0)
        {
            return(true);
        }
        BestHTTP.Decompression.Crc.CRC32 checker = new BestHTTP.Decompression.Crc.CRC32();
        using (FileStream stream = File.OpenRead(path))
        {
            uint result = (uint)checker.GetCrc32(stream);
            //Debug.Log("CheckCrc " + path + " " + result + " " + crc + " " + (int)result + " " + (int)crc);
            if (result == crc)
            {
                return(true);
            }
        }

        return(false);
    }
Ejemplo n.º 3
0
 // This ctor is private - no validation is done here.  This is to allow the use
 // of a (specific) negative value for the _lengthLimit, to indicate that there
 // is no length set.  So we validate the length limit in those ctors that use an
 // explicit param, otherwise we don't validate, because it could be our special
 // value.
 private CrcCalculatorStream
     (bool leaveOpen, Int64 length, System.IO.Stream stream, CRC32 crc32)
     : base()
 {
     _innerStream = stream;
     _Crc32 = crc32 ?? new CRC32();
     _lengthLimit = length;
     _leaveOpen = leaveOpen;
 }
Ejemplo n.º 4
0
 /// <summary>
 ///   A constructor allowing the specification of the length of the stream
 ///   to read, as well as whether to keep the underlying stream open upon
 ///   Close(), and the CRC32 instance to use.
 /// </summary>
 /// <remarks>
 ///   <para>
 ///     The stream uses the specified CRC32 instance, which allows the
 ///     application to specify how the CRC gets calculated.
 ///   </para>
 /// </remarks>
 /// <param name="stream">The underlying stream</param>
 /// <param name="length">The length of the stream to slurp</param>
 /// <param name="leaveOpen">true to leave the underlying stream
 /// open upon close of the <c>CrcCalculatorStream</c>; false otherwise.</param>
 /// <param name="crc32">the CRC32 instance to use to calculate the CRC32</param>
 public CrcCalculatorStream(System.IO.Stream stream, Int64 length, bool leaveOpen,
                            CRC32 crc32)
     : this(leaveOpen, length, stream, crc32)
 {
     if (length < 0)
         throw new ArgumentException("length");
 }