aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-09-06 17:35:10 +0100
committerMichael Williamson <mike@zwobble.org>2015-09-06 17:35:10 +0100
commitcccaa16098484a7d9df26c18c0b6aa5b9defbeb5 (patch)
tree2df9fc9050639651315d29ec24b2b65f9ed55d07 /lib
parente16404b95f86cd0d938f1f9ebc4bacd7a5aa7042 (diff)
Extract uriToPath
Diffstat (limited to 'lib')
-rw-r--r--lib/docx/files.js19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/docx/files.js b/lib/docx/files.js
index 6596a01..6e6f797 100644
--- a/lib/docx/files.js
+++ b/lib/docx/files.js
@@ -4,15 +4,12 @@ var promises = require("../promises");
exports.Files = Files;
+exports.uriToPath = uriToPath;
function Files() {
- function read(path, encoding) {
- // TODO: check whether this works for Windows file URIs
- var fileUriPrefix = "file:///";
- if (startsWith(path, fileUriPrefix)) {
- return readFile(path.slice(fileUriPrefix.length - 1), encoding);
- }
+ function read(uri, encoding) {
+ return readFile(uriToPath(uri), encoding);
}
return {
@@ -22,6 +19,16 @@ function Files() {
var readFile = promises.promisify(fs.readFile.bind(fs));
+
+function uriToPath(uri) {
+ var fileUriPrefix = "file:///";
+ if (startsWith(uri, fileUriPrefix)) {
+ return uri.slice(fileUriPrefix.length - 1);
+ } else {
+ throw new Error("Could not convert URI to path: " + uri);
+ }
+}
+
function startsWith(string, search) {
return string.indexOf(search) === 0;
}