diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-09-06 11:32:11 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-09-06 11:34:31 +0100 |
| commit | ca74aa92bdc45f7777a66304745b3cf153a6c98e (patch) | |
| tree | 7f7ebddc90d79363958dfd6c4d7edb9fd0a3e6e3 /lib | |
| parent | e1344467f2301c122f8ce00b2ddf29db92bc90d2 (diff) | |
Add support for reading file URIs
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/docx/files.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/docx/files.js b/lib/docx/files.js new file mode 100644 index 0000000..6596a01 --- /dev/null +++ b/lib/docx/files.js @@ -0,0 +1,27 @@ +var fs = require("fs"); + +var promises = require("../promises"); + + +exports.Files = Files; + + +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); + } + } + + return { + read: read + }; +} + +var readFile = promises.promisify(fs.readFile.bind(fs)); + +function startsWith(string, search) { + return string.indexOf(search) === 0; +} |
