Revision 14e712ee802da2a6199653268f8519187ece2c51 authored by Alex Lam S.L on 09 May 2018, 22:16:35 UTC, committed by GitHub on 09 May 2018, 22:16:35 UTC
fixes #3127
1 parent f83adcc
fetch.js
var fs = require("fs");
var path = require("path");
try {
fs.mkdirSync("./tmp");
} catch (e) {
if (e.code != "EEXIST") throw e;
}
function local(url) {
return path.join("./tmp", encodeURIComponent(url));
}
function read(url) {
return fs.createReadStream(local(url));
}
module.exports = function(url, callback) {
var result = read(url);
result.on("error", function(e) {
if (e.code != "ENOENT") return callback(e);
require(url.slice(0, url.indexOf(":"))).get(url, function(res) {
if (res.statusCode !== 200) return callback(res);
res.pipe(fs.createWriteStream(local(url)).on("close", function() {
callback(null, read(url));
}));
});
}).on("open", function() {
callback(null, result);
});
};
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...