Skip to content Skip to sidebar Skip to footer

Js - How To Compute Md5 On Binary Data

EDIT: changed title from 'JS File API - write and read UTF-8 data is inconsistent' to reflect the actual question. I have some binary content i need to calculate the MD5 of. The co

Solution 1:

Basically I tried another route and converted the blob file back to arraybuffer and computed the MD5 on that. At that point, the file's MD5 and the arraybuffer's are the same.

var b = new Blob(arrayBuffers, {type: "text/plain;charset=utf-8"});
            var blobHtml = new Blob( [str2ab(o_request.main_page_html)], {type: "text/plain;charset=utf-8"} );

f = new FileReader();
f.readAsArrayBuffer(b);
f.onloadend = function(a){
  var warcMD5 = faultylabs.MD5(this.result);
  var fd = new FormData();
  fd.append('warc_file', b)
  fd.append('warc_checksum_md5', warcMD5.toLowerCase());

  uploadData(fd);
}

I guess the result from a binary string and from a buffer array is different, that's why also the MD5 is inconsistent.

Post a Comment for "Js - How To Compute Md5 On Binary Data"