satazor / js-spark-md5

Lightning fast normal and incremental md5 for javascript
Do What The F*ck You Want To Public License
2.46k stars 469 forks source link

Inconsistency between computation #12

Closed octplane closed 11 years ago

octplane commented 11 years ago

Hi,

I've been playing with SparkMD5 a bit and I'm now facing some curious behavior from the library:


var a = new Uint8Array(4);
// fill up with ASCII
a[0] = 65; a[1] = 66; a[2] = 67; a[3] = 68;
var equivalentString = String.fromCharCode.apply(null, new Uint8Array(a));

var arraySpark = new SparkMD5();
arraySpark.appendBinary(a);
console.log("Array Spark: %s", arraySpark.end());
// => Array Spark: b2c0119607b38477963f46526b4d162f

var stringSpark = new SparkMD5();
stringSpark.appendBinary(equivalentString);
console.log("String Spark: %s", stringSpark.end());
// => String Spark: cb08ca4a7bb5f9683c19133a84872ca7

I was expecting the two values to be identical. Am I doing something wrong ?

From the other MD5 implementations available online, I'm expecting "cb08ca4a7bb5f9683c19133a84872ca7".

satazor commented 11 years ago

For ArrayBuffers please use:

var a = new Uint8Array(4);
// fill up with ASCII
a[0] = 65; a[1] = 66; a[2] = 67; a[3] = 68;

var arraySpark = new SparkMD5.ArrayBuffer();
arraySpark.append(a);
console.log("Array Spark: %s", arraySpark.end());
octplane commented 11 years ago

Oh Great, I thought the API was more magical than it is, that's better ! Thank you for the quick reply !

satazor commented 11 years ago

I decided to split them in two separate classes to avoid performance issues with type/flag checks.