Created
November 21, 2012 11:20
-
-
Save piscis/4124412 to your computer and use it in GitHub Desktop.
CRC32 Tests NodeJS/PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var crc32 = require('buffer-crc32'); // npm install buffer-crc32; | |
var crc = require('crc'); // npm install crc | |
var str = "Hello CRC"; | |
var strUTF8= "<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body><p>自動販売</p></body></html>"; | |
var bufUTF8 = new Buffer(strUTF8); | |
var bufStr = new Buffer(str); | |
// Example 1 | |
console.log("Buffer CRC32 implementation:") | |
console.log('Example 1 bufUTF8 (signed): '+crc32.signed(bufUTF8 )); // returns 1395090196 | |
console.log('Example 1 strUTF8 (signed): '+crc32.signed(strUTF8)); // returns 1395090196 | |
console.log('Example 1 bufUTF8 (unsigned): '+crc32.unsigned(bufUTF8 )); // returns 1395090196 | |
console.log('Example 1 strUTF8 (unsigned): '+crc32.unsigned(strUTF8)); // returns 1395090196 | |
console.log(""); | |
console.log("Current express dependency (node-crc):"); | |
console.log('Example 1 strUTF8 (unsigned):'+ crc.crc32(strUTF8)); // return -81823478 | |
console.log('Example 1 bufUTF8 (unsigned):'+ crc.crc32(bufUTF8.toString())); // returns -81823478 | |
console.log("\n"); | |
console.log("Buffer CRC32 implementation:") | |
console.log("Example 2 bufStr (unsigned): "+crc32.unsigned(bufStr)); // returns -2034458343 | |
console.log("Example 2 str (unsigned): "+crc32.unsigned(str)); // returns -2034458343 | |
console.log(""); | |
console.log("Current express dependency (node-crc):"); | |
console.log("Example 2 str (unsigned): "+crc.crc32(str)); // return -2034458343 | |
console.log("Example 2 str (unsigned): "+crc.crc32(bufStr.toString())); // returns -2034458343 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo crc32("<!DOCTYPE html>\n<html>\n<head>\n</head>\n<body><p>自動販売</p></body></html>").PHP_EOL; | |
// returns 1395090196 | |
echo crc32("Hello CRC").PHP_EOL; | |
// returns 2260508953 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tested with buffer-crc32, and for the Example 2 str/bufStr I got the same return value as PHP (and not, as your comments suggest, a different signed number). I guess a faulty comment here?