var {Cc, Ci} = require("chrome");

// return the two-digit hexadecimal code for a byte
function toHexString(charCode) {
    return ("0" + charCode.toString(16)).slice(-2);
}

function md5File(path) {
    var f = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
    f.initWithPath(path);
    var istream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
    // open for reading
    istream.init(f, 0x01, 0444, 0);
    var ch = Cc["@mozilla.org/security/hash;1"].createInstance(Ci.nsICryptoHash);
    // we want to use the MD5 algorithm
    ch.init(ch.MD5);
    // this tells updateFromStream to read the entire file
    const PR_UINT32_MAX = 0xffffffff;
    ch.updateFromStream(istream, PR_UINT32_MAX);
    // pass false here to get binary data back
    var hash = ch.finish(false);

    // convert the binary hash data to a hex string.
    var s = [toHexString(hash.charCodeAt(i)) for (i in hash)].join("");
    return s;
}

exports.hashFile = md5File;

@@ -1,11 +1,13 @@
-var
+const
  %7BCc, Ci
@@ -22,16 +22,16 @@
 ire(
-%22
+'
 chrome
-%22
+'
 );%0A%0A
@@ -82,24 +82,19 @@
  a byte%0A
-function
+let
  toHexSt
@@ -97,16 +97,19 @@
 exString
+ = 
 (charCod
@@ -115,25 +115,15 @@
 de) 
-%7B%0A    return (%220%22
+=%3E ('0'
  + c
@@ -159,27 +159,20 @@
 2);%0A
-%7D%0A%0Afunction
+%0Alet
  md5File
 (pat
@@ -171,32 +171,38 @@
 File
+ = 
 (path)
+ =%3E
  %7B%0A    
-var
+let
  f = Cc%5B
 %22@mo
@@ -193,25 +193,25 @@
  let f = Cc%5B
-%22
+'
 @mozilla.org
@@ -223,17 +223,17 @@
 /local;1
-%22
+'
 %5D.create
@@ -285,23 +285,24 @@
 (path);%0A
+%0A
     
-var
+let
  istream
@@ -303,25 +303,25 @@
 stream = Cc%5B
-%22
+'
 @mozilla.org
@@ -348,17 +348,17 @@
 stream;1
-%22
+'
 %5D.create
@@ -390,16 +390,17 @@
 tream);%0A
+%0A
     // o
@@ -451,23 +451,24 @@
 44, 0);%0A
+%0A
     
-var
+let
  ch = Cc
@@ -468,17 +468,17 @@
 ch = Cc%5B
-%22
+'
 @mozilla
@@ -497,17 +497,17 @@
 y/hash;1
-%22
+'
 %5D.create
@@ -534,16 +534,17 @@
 oHash);%0A
+%0A
     // w
@@ -596,16 +596,17 @@
 h.MD5);%0A
+%0A
     // t
@@ -743,16 +743,17 @@
 2_MAX);%0A
+%0A
     // p
@@ -795,19 +795,19 @@
 ack%0A    
-var
+let
  hash = 
@@ -886,11 +886,11 @@
     
-var
+let
  s =
@@ -949,10 +949,10 @@
 oin(
-%22%22
+''
 );%0A 
@@ -965,16 +965,17 @@
 urn s;%0A%7D
+;
 %0A%0Aexport

Update md5.js code.