Last active
April 27, 2017 13:55
-
-
Save anchnk/74873396cf6424802be7077890f450cd to your computer and use it in GitHub Desktop.
WHATWG file URL doc examples https://github.com/nodejs/node/pull/12670
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const fs = require('fs'); | |
const { URL } = require('url'); | |
const hosts_file_url = new URL(`file://hostname/p/a/t/h/file.txt`); | |
fs.readFile(hosts_file_url, 'utf-8', (err,data) => { | |
if (err) throw err; // error is throw | |
console.log(data); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const fs = require('fs'); | |
const { URL } = require('url'); | |
const hosts_file_url = new URL(`file://hostname/p/a/t/h/file.txt`); // path convereted to UNC | |
fs.readFile(hosts_file_url, 'utf-8', (err,data) => { | |
if (err) throw err; | |
console.log(data); // read file's content | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const fs = require('fs'); | |
const { URL } = require('url'); | |
const hosts_file_url = new URL('file:///etc/hosts'); | |
fs.readFile(hosts_file_url, 'utf-8', (err,data) => { | |
if (err) throw err; | |
console.log(data); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const fs = require('fs'); | |
const { URL } = require('url'); | |
const hosts_file_url = new URL(`file:///${process.env['SystemRoot']}/System32/drivers/etc/hosts`); | |
fs.readFile(hosts_file_url, 'utf-8', (err,data) => { | |
if (err) throw err; | |
console.log(data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment