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 470 forks source link

spark.end(); The results after two executions are different #55

Closed guoyiheng closed 3 years ago

guoyiheng commented 4 years ago

worng code: spark.end() executed twice

console.log(spark.end())
callBack(spark.end())

true code:

 tmp_md5 = spark.end()
 callBack(tmp_md5)

I found that the results after two executions are different. the executions code is spark.end()

I didn't look at the source code carefully, so I hope the author answers

charliemday commented 4 years ago

On calling spark.end() the internal spark state resets itself (see line: 506 - https://github.com/satazor/js-spark-md5/blob/c3d964c605befba62d608d2c0fe3dfbf06e251fb/spark-md5.js#L506)

The work around for this could be to save the current state and reset the state immediately before calling spark.end() again.

e.g.

const sparkState = spark.getState(); console.log('Correct MD5', spark.end()); console.log('Reset MD5', spark.end()); spark.setState(sparkState); console.log('Correct MD5, spark.end());

guoyiheng commented 3 years ago

I understand, thank you