ICSharpCode.SharpZipLib.Checksum.BZip2Crc.Update C# (CSharp) Méthode

Update() public méthode

Update CRC data checksum based on a portion of a block of data
public Update ( byte buffer, int offset, int count ) : void
buffer byte Contains the data to update the CRC with.
offset int The offset into the buffer where the data starts
count int The number of data bytes to update the CRC with.
Résultat void
        public void Update(byte[] buffer, int offset, int count)
        {
            if (buffer == null) {
                throw new ArgumentNullException(nameof(buffer));
            }

            if (offset < 0) {
                throw new ArgumentOutOfRangeException(nameof(offset), "cannot be less than zero");
            }

            if (offset >= buffer.Length) {
                throw new ArgumentOutOfRangeException(nameof(offset), "not a valid index into buffer");
            }

            if (count < 0) {
                throw new ArgumentOutOfRangeException(nameof(count), "cannot be less than zero");
            }

            if (offset + count > buffer.Length) {
                throw new ArgumentOutOfRangeException(nameof(count), "exceeds buffer size");
            }

            for (int i = 0; i < count; ++i) {
                Update(buffer[offset++]);
            }
        }

Same methods

BZip2Crc::Update ( byte buffer ) : void
BZip2Crc::Update ( int bval ) : void

Usage Example

    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;
    }
All Usage Examples Of ICSharpCode.SharpZipLib.Checksum.BZip2Crc::Update