Skip to content

Commit d0bd6f8

Browse files
TooTallNatemathiasjakobsenViliusSutkus89
committedJan 23, 2019
Handle filenames with 'file://' shema
For Electron. Fixes #29. Closes #40. Co-authored-by: Mathias Jakobsen <mathiasjakobsen@me.com> Co-authored-by: Vilius Sutkus <ViliusSutkus89@gmail.com>
1 parent b591acd commit d0bd6f8

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed
 

‎bindings.js

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
var fs = require('fs')
77
, path = require('path')
8+
, fileURLToPath = require('file-uri-to-path')
89
, join = path.join
910
, dirname = path.dirname
1011
, exists = ((fs.accessSync && function (path) { try { fs.accessSync(path); } catch (e) { return false; } return true; })
@@ -138,6 +139,12 @@ exports.getFileName = function getFileName (calling_file) {
138139
Error.prepareStackTrace = origPST
139140
Error.stackTraceLimit = origSTL
140141

142+
// handle filename that starts with "file://"
143+
var fileSchema = "file://";
144+
if (fileName.indexOf(fileSchema) === 0) {
145+
fileName = fileURLToPath(fileName);
146+
}
147+
141148
return fileName
142149
}
143150

‎package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@
2121
"url": "https://github.com/TooTallNate/node-bindings/issues"
2222
},
2323
"homepage": "https://github.com/TooTallNate/node-bindings",
24-
"license": "MIT"
24+
"license": "MIT",
25+
"dependencies": {
26+
"file-uri-to-path": "1.0.0"
27+
}
2528
}

0 commit comments

Comments
 (0)
Please sign in to comment.