Bug 1356306 - Additional fix: make nsIInputStream.readBytes() loop while data is available. r=jorgk a=jorgk
authoraceman <acelists@atlas.sk>
Sun, 16 Apr 2017 12:58:00 +0200
changeset 24467 d6ba4d8b1bcf
parent 24466 b850fc61a632
child 24468 1694f6f2b300
push id2059
push usermozilla@jorgk.com
push dateMon, 17 Apr 2017 06:53:03 +0000
treeherdercomm-aurora@9d19a9b732a0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk, jorgk
bugs1356306
Bug 1356306 - Additional fix: make nsIInputStream.readBytes() loop while data is available. r=jorgk a=jorgk
mailnews/compose/content/mailComposeEditorOverlay.xul
--- a/mailnews/compose/content/mailComposeEditorOverlay.xul
+++ b/mailnews/compose/content/mailComposeEditorOverlay.xul
@@ -120,21 +120,25 @@
     function GenerateDataURL(url) {
       var file = Services.io.newURI(url, null, null)
         .QueryInterface(Components.interfaces.nsIFileURL).file;
       var contentType = Components.classes["@mozilla.org/mime;1"]
         .getService(Components.interfaces.nsIMIMEService)
         .getTypeFromFile(file);
       var inputStream = Components.classes["@mozilla.org/network/file-input-stream;1"]
         .createInstance(Components.interfaces.nsIFileInputStream);
-      inputStream.init(file, 0x01, 0600, 0);
+      inputStream.init(file, 0x01, 0o600, 0);
       var stream = Components.classes["@mozilla.org/binaryinputstream;1"]
         .createInstance(Components.interfaces.nsIBinaryInputStream);
       stream.setInputStream(inputStream);
-      var encoded = btoa(stream.readBytes(stream.available()));
+      let data = "";
+      while (stream.available() > 0) {
+        data += stream.readBytes(stream.available());
+      }
+      let encoded = btoa(data);
       stream.close();
       return "data:" + contentType +
         ";filename=" + encodeURIComponent(file.leafName) +
         ";base64," + encoded;
     }
   ]]>
   </script>