A little more information: I'm interested in modifying the MediaWiki extension MsUpload [1][2]. To expose the MsUpload object to the javascript console, I've modified MsUpload.js to add "window.MsUpload = MsUpload" at the end [3] in my local version (not in the [3] link). In my console I then add CryptoJS core and sha1 from [4] and [5].
I'm then able to attempt to get a sha1 hash of a file by doing:
var file = MsUpload.uploader.files[0];
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
var sha1 = CryptoJS.SHA1( e.target.result ).toString();
console.log( sha1 );
};
})(file);
And initiate the onload event with one of these:
reader.readAsDataURL( file.getNative() ); // no error but incorrect sha1
reader.readAsText( file.getNative() ); // no error but incorrect sha1
reader.readAsBinaryString( file.getNative() ); // no error but incorrect sha1
reader.readAsArrayBuffer( file.getNative() ); // fails in chrome
Thank you for any assistance.
[1] https://www.mediawiki.org/wiki/Extension:MsUpload
[2] https://github.com/wikimedia/mediawiki-extensions-MsUpload
[3] https://github.com/wikimedia/mediawiki-extensions-MsUpload/blob/master/MsUpload.js#L499
[4] https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/core-min.js
[5] https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/sha1.js