Example #1
0
        public static uint GetCrc32(byte[] buffer, int offset, int length)
        {
            var crc32 = new QwCrc32();

            crc32.Update(buffer, offset, length);
            return(crc32.Value);
        }
Example #2
0
        public static uint GetFileCrc32(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            var crc32 = new QwCrc32();
            var buf   = new byte[4096];

            using (var fs = new FileStream(path, FileMode.Open))
            {
                int len = 0;
                while ((len = fs.Read(buf, 0, buf.Length)) != 0)
                {
                    crc32.Update(buf, 0, len);
                }
            }
            return(crc32.Value);
        }
Example #3
0
        public static uint GetStreamCrc32(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (!stream.CanRead)
            {
                throw new ArgumentException("stream is not readable.");
            }
            stream.Position = 0;
            QwCrc32 crc32 = new QwCrc32();

            byte[] buf = new byte[4096];
            int    len = 0;

            while ((len = stream.Read(buf, 0, buf.Length)) != 0)
            {
                crc32.Update(buf, 0, len);
            }
            stream.Position = 0;
            return(crc32.Value);
        }