public static string GetCrc32String(byte[] buffer) { Crc32Hash crc32 = new Crc32Hash(); crc32.Append(buffer); byte[] retVal = crc32.Finish(); return(BitConverter.ToString(retVal).Replace("-", "")); }
/// <summary> /// /// </summary> /// <param name="buffer"></param> /// <returns></returns> public static byte[] GetCrc32Bytes(byte[] buffer) { if (buffer == null) { throw new ArgumentNullException("buffer"); } Crc32Hash crc32 = new Crc32Hash(); crc32.Append(buffer); return(crc32.Finish()); }
/// <summary> /// /// </summary> /// <param name="buffer"></param> /// <returns></returns> public static string GetCrc32String(byte[] buffer) { if (buffer == null) { throw new ArgumentNullException("buffer"); } Crc32Hash crc32 = new Crc32Hash(); crc32.Append(buffer); byte[] retVal = crc32.Finish(); return(BitConverter.ToString(retVal).Replace("-", "")); }
public override void Copy(string sourceFile, string destFile) { _map(); FtpUrlInfo urlSource = new FtpUrlInfo(sourceFile); FtpUrlInfo urlDest = new FtpUrlInfo(destFile); if (urlSource.Scheme == "sftp") { var entry = _entries[urlSource.Path]; if (_db.Exists(urlSource.Path, entry)) { var data = _db.Get(urlSource.Path); File.WriteAllBytes(destFile, data); } else { DbDebugHelper.OnSftpUpdate("downloading " + urlSource.Path); _sftp.Get(urlSource.Path, destFile); DbDebugHelper.OnSftpUpdate("caching " + urlSource.Path); _db.Set(destFile, urlSource.Path, entry); } } else { if (_entries.ContainsKey(urlDest.Path)) { var entry = _entries[urlDest.Path]; if (_db.Exists(urlDest.Path, entry)) { byte[] dataDest = _db.Get(urlDest.Path); byte[] dataSource = File.ReadAllBytes(sourceFile); Crc32Hash hash = new Crc32Hash(); if (dataDest.Length == dataSource.Length && hash.ComputeHash(dataDest) == hash.ComputeHash(dataSource)) { // do not upload the same file } else { DbDebugHelper.OnSftpUpdate("uploading " + urlDest.Path); _sftp.Put(sourceFile, urlDest.Path); DbDebugHelper.OnSftpUpdate("updating cached version for " + urlDest.Path); var newEntry = _sftp.GetFileListAdv(urlDest.Path)[0]; _db.Set(sourceFile, urlDest.Path, newEntry); _entries[urlDest.Path] = newEntry; } } else { DbDebugHelper.OnSftpUpdate("uploading " + urlDest.Path); _sftp.Put(sourceFile, urlDest.Path); DbDebugHelper.OnSftpUpdate("updating cached version for " + urlDest.Path); var newEntry = _sftp.GetFileListAdv(urlDest.Path)[0]; _db.Set(sourceFile, urlDest.Path, newEntry); _entries[urlDest.Path] = newEntry; } } else { DbDebugHelper.OnSftpUpdate("uploading new file " + urlDest.Path); _sftp.Put(sourceFile, urlDest.Path); } } }