aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
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;
}