diff --git a/examples/Crc32.cpp b/examples/Crc32.cpp index 74e625b..e8f1d74 100644 --- a/examples/Crc32.cpp +++ b/examples/Crc32.cpp @@ -11,8 +11,24 @@ /* Note that uWS::SSLApp({options}) is the same as uWS::App() when compiled without SSL support */ -#include #include +#include +#include + +uint32_t crc32(const char *s,size_t n, uint32_t crc=0xFFFFFFFF) { + + for(size_t i=0;i>=1; + if(b) crc=crc^0xEDB88320; + ch>>=1; + } + } + + return crc; +} int main() { @@ -29,15 +45,15 @@ int main() { } auto isAborted = std::make_shared(false); - uLong crc = crc32(0L, Z_NULL, 0); + uint32_t crc = 0xFFFFFFFF; res->onData([res, isAborted, crc](std::string_view chunk, bool isFin) mutable { if (chunk.length()) { - crc = crc32(crc, (const Bytef *) chunk.data(), (uInt) chunk.length()); + crc = crc32(chunk.data(), chunk.length(), crc); } if (isFin && !*isAborted) { std::stringstream s; - s << std::hex << crc << std::endl; + s << std::hex << (~crc) << std::endl; res->end(s.str()); } });