blob: 4e3a8207791eea5435d30536829953c57079cf1f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
var fs = require("fs");
var url = require("url");
var promises = require("../promises");
exports.Files = Files;
exports.uriToPath = uriToPath;
function Files() {
function read(uri, encoding) {
return readFile(uriToPath(uri), encoding);
}
return {
read: read
};
}
var readFile = promises.promisify(fs.readFile.bind(fs));
function uriToPath(uriString) {
var uri = url.parse(uriString);
if (uri.protocol === "file:" && (!uri.host || uri.host === "localhost")) {
return decodeURIComponent(uri.path);
} else {
throw new Error("Could not convert URI to path: " + uriString);
}
}
|