Sha256: 26de677c5ab0d5774135c6789c3909f205db28b112abdf9d7c7ffbbc3e61a82d
Contents?: true
Size: 1.29 KB
Versions: 4
Compression:
Stored size: 1.29 KB
Contents
var fs = require("fs"); global.XMLHttpRequest = function XMLHttpRequest() { var self = this, info = self._info = {}, headers = {}, url; // TODO handle file system errors? self.open = function(m, u, a) { info.url = u; info.async = a; self.send = a ? read : readSync; }; self.setRequestHeader = function(n, v) { if (/^Accept$/i.test(n)) info.mimeType = v.split(/,/g)[0]; }; function read() { fs.readFile(info.url, "binary", function(e, d) { if (e) { self.status = 404; // assumed } else { self.status = 200; self.responseText = d; self.responseXML = {_xml: d}; headers["Content-Length"] = d.length; } self.readyState = 4; XMLHttpRequest._last = self; if (self.onreadystatechange) self.onreadystatechange(); }); } function readSync() { try { var d = fs.readFileSync(info.url, "binary"); self.status = 200; self.responseText = d; self.responseXML = {_xml: d}; headers["Content-Length"] = d.length; } catch (e) { self.status = 404; // assumed } self.readyState = 4; XMLHttpRequest._last = self; if (self.onreadystatechange) self.onreadystatechange(); } self.getResponseHeader = function(n) { return headers[n]; }; };
Version data entries
4 entries across 4 versions & 2 rubygems