Update() 공개 메소드

Updates the CRC data checksum with the bytes taken from a block of data.
public Update ( byte buffer ) : void
buffer byte Contains the data to update the CRC with.
리턴 void
예제 #1
0
    public static int Main(string[] args)
    {
        if (args.Length == 0) {
            ShowHelp();
            return 1;
        }

        var parser = new ArgumentParser(args);

        if (!File.Exists(file_)) {
            Console.Error.WriteLine("Cannot find file {0}", file_);
            ShowHelp();
            return 1;
        }

        using (FileStream checksumStream = File.OpenRead(file_)) {

            byte[] buffer = new byte[4096];
            int bytesRead;

            switch (parser.Command) {
                case Command.Help:
                    ShowHelp();
                    break;

                case Command.Crc32:
                    var currentCrc = new Crc32();
                    while ((bytesRead = checksumStream.Read(buffer, 0, buffer.Length)) > 0) {
                        currentCrc.Update(buffer, 0, bytesRead);
                    }
                    Console.WriteLine("CRC32 for {0} is 0x{1:X8}", args[0], currentCrc.Value);
                    break;

                case Command.BZip2:
                    var currentBZip2Crc = new BZip2Crc();
                    while ((bytesRead = checksumStream.Read(buffer, 0, buffer.Length)) > 0) {
                        currentBZip2Crc.Update(buffer, 0, bytesRead);
                    }
                    Console.WriteLine("BZip2CRC32 for {0} is 0x{1:X8}", args[0], currentBZip2Crc.Value);
                    break;

                case Command.Adler:
                    var currentAdler = new Adler32();
                    while ((bytesRead = checksumStream.Read(buffer, 0, buffer.Length)) > 0) {
                        currentAdler.Update(buffer, 0, bytesRead);
                    }
                    Console.WriteLine("Adler32 for {0} is 0x{1:X8}", args[0], currentAdler.Value);
                    break;
            }
        }
        return 0;
    }
예제 #2
0
        public void CRC_32_BZip2()
        {
            var underTestBZip2Crc = new BZip2Crc();
            Assert.AreEqual(0x0, underTestBZip2Crc.Value);

            underTestBZip2Crc.Update(check);
            Assert.AreEqual(0xFC891918, underTestBZip2Crc.Value);

            underTestBZip2Crc.Reset();
            Assert.AreEqual(0x0, underTestBZip2Crc.Value);

            exceptionTesting(underTestBZip2Crc);
        }