Ticket #2018: html5-send-binary.patch
File html5-send-binary.patch, 1.8 KB (added by , 8 weeks ago) |
---|
-
html5/js/lib/bencode.js
26 26 throw "invalid: cannot encode null"; 27 27 } 28 28 switch(btypeof(obj)) { 29 case "binary": return bbinary(obj); 29 30 case "string": return bstring(obj); 30 31 case "number": return bint(obj); 31 32 case "list": return blist(obj); … … 145 146 146 147 // returns the bencoding type of the given object 147 148 function btypeof(obj) { 149 try { 150 if (obj instanceof Uint8Array) { 151 return "binary"; 152 } 153 } 154 catch {} 148 155 var type = typeof obj; 149 156 if(type === 'object') { 150 157 if(typeof obj.length === 'undefined') { … … 160 167 return (str.length + ":" + str); 161 168 } 162 169 170 function bbinary(u8a) { 171 const CHUNK_SZ = 0x8000; 172 const c = [ 173 ""+u8a.length, 174 ":" 175 ]; 176 for (let i=0; i < u8a.length; i+=CHUNK_SZ) { 177 c.push(String.fromCharCode.apply(null, u8a.subarray(i, i+CHUNK_SZ))); 178 } 179 return c.join(""); 180 } 181 163 182 // bencode an integer 164 183 function bint(num) { 165 184 return "i" + num + "e"; -
html5/index.html
946 946 const fileReader = new FileReader(); 947 947 fileReader.onloadend = function (evt) { 948 948 const u8a = new Uint8Array(evt.target.result); 949 const buf = Utilities.Uint8ToString(u8a); 950 client.send_file(f.name, f.type, f.size, buf); 949 //const buf = Utilities.Uint8ToString(u8a); 950 //clog("buf("+evt.target.result+")="+buf.length); 951 client.send_file(f.name, f.type, f.size, u8a); 951 952 }; 952 953 fileReader.readAsArrayBuffer(f); 953 954 }