This is very nice :) -----Original Message----- From: Alex Henderson [mailto:Alex.Henderson@surfacespectra.com] Sent: Tuesday, June 10, 2003 6:38 AM To: Boost-Users@yahoogroups.com Subject: RE: [Boost-Users] [crc] Simple example please Superb! Thanks, Alex
-----Original Message----- From: Vladimir Prus [mailto:ghost@cs.msu.su] Sent: 10 June 2003 06:08 To: boost-users@yahoogroups.com Subject: [Boost-Users] [crc] Simple example please
Hi Alex,
I'd like to calculate a value for a cyclic redundancy check (crc) for a number of files.
This isn't going to be transmitted anywhere, I simply want to compare the values to see whether the files are exactly the same. I know I can simply check byte for byte, but I've got a few thousand files and it's easier to calculate the crc for each and see whether any are the same first.
Here's the function that I use for the same purpose. Might not be optimal, but works:
unsigned file_crc(const string& name) { #if defined(__GNUC__) && __GNUC__ < 3 ifstream ifs(name.c_str(), ios::binary); #else ifstream ifs(name.c_str(), ios_base::binary); #endif if (!ifs) return 0; else { using namespace boost;
crc_32_type crc32; int c; while( (c = ifs.rdbuf()->sbumpc()) != -1) crc32.process_byte(char(c)); return crc32.checksum(); } }
I believe some example of this kind should be included... Daryle, what do you think?
HTH, Volodya
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Yahoo! Groups Sponsor Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. [Non-text portions of this message have been removed]