diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-09-07 20:39:54 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-09-07 20:39:54 +0100 |
| commit | 2596c1c7122096874d00d7c5392d4ffb482e31b6 (patch) | |
| tree | 9eea4c367538cc5b7c0554e7f7d3299dc82d166d /lib/docx/files.js | |
| parent | 20406f3b17d2bb188b78c22602b79684086798d1 (diff) | |
Continue with warning when failing to read image
Diffstat (limited to 'lib/docx/files.js')
| -rw-r--r-- | lib/docx/files.js | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/docx/files.js b/lib/docx/files.js index 2d0963b..0e95197 100644 --- a/lib/docx/files.js +++ b/lib/docx/files.js @@ -2,6 +2,7 @@ var fs = require("fs"); var url = require("url"); var os = require("os"); var resolvePath = require("path").resolve; +var isAbsolutePath = require('path-is-absolute'); var promises = require("../promises"); @@ -12,7 +13,20 @@ exports.uriToPath = uriToPath; function Files(base) { function read(uri, encoding) { - return readFile(resolvePath(base, uriToPath(uri)), encoding); + return resolveUri(uri).then(function(path) { + return readFile(path, encoding); + }); + } + + function resolveUri(uri) { + var path = uriToPath(uri); + if (isAbsolutePath(path)) { + return promises.resolve(path); + } else if (base) { + return promises.resolve(resolvePath(base, path)); + } else { + return promises.reject(new Error("could not find external image '" + uri + "', path of input document is unknown")); + } } return { |
