zipios 2.3.4
Zipios -- a small C++ library providing easy access to .zip files.
zcrc32.cpp
Go to the documentation of this file.
1
2
3#include <fstream>
4#include <iomanip>
5#include <iostream>
6
7#include <zlib.h>
8
9
10int main(int argc, char *argv[])
11{
12 if(argc != 2)
13 {
14 std::cerr << "Usage: " << argv[0] << " <filename>\n";
15 return 1;
16 }
17
18 std::ifstream in(argv[1]);
19 if(!in)
20 {
21 std::cerr << "error: could not access file \"" << argv[1] << "\".\n";
22 return 1;
23 }
24
25 int result(crc32(0, nullptr, 0));
26 for(;;)
27 {
28 char buf[64 * 1024];
29 in.read(buf, sizeof(buf));
30 if(in.gcount() == 0)
31 {
32 break;
33 }
34 result = crc32(result, reinterpret_cast<Bytef const *>(buf), in.gcount());
35 }
36
37 std::cout << std::hex << std::setw(8) << std::setfill('0') << result << "\n";
38
39 return 0;
40}
41
42// vim: ts=4 sw=4 et
int main(int argc, char *argv[])
Definition zcrc32.cpp:10