NotFound: No such file or directory (os error 2): open '/etc/hosts'
at Object.open (ext:deno_fs/30_fs.js:633:21)
at Object.open (ext:deno_node/_fs/_fs_open.ts:80:10)
at ReadStream._construct (ext:deno_node/internal/fs/streams.mjs:63:17)
at constructNT (ext:deno_node/_stream.mjs:1672:16)
at processTicksAndRejections (ext:deno_node/_next_tick.ts:33:15)
at runNextTicks (ext:deno_node/_next_tick.ts:75:3)
at eventLoopTick (ext:core/01_core.js:182:21)
exports.getFile = function (filePath, preserveFormatting, cb) {
var lines = []
if (typeof cb !== 'function') {
fs.readFileSync(filePath, { encoding: 'utf8' }).split(/\r?\n/).forEach(online)
return lines
}
cb = once(cb)
fs.createReadStream(filePath, { encoding: 'utf8' }) //.on('error', cb)
.pipe(split())
.pipe(through(online))
.on('close', function () {
cb(null, lines)
})
.on('error', cb)
function online (line) {
// Remove all comment text from the line
var lineSansComments = line.replace(/#.*/, '')
var matches = /^\s*?(.+?)\s+(.+?)\s*$/.exec(lineSansComments)
if (matches && matches.length === 3) {
// Found a hosts entry
var ip = matches[1]
var host = matches[2]
lines.push([ip, host])
} else {
// Found a comment, blank line, or something else
if (preserveFormatting) {
lines.push(line)
}
}
}
}
NotFound: No such file or directory (os error 2): open '/etc/hosts'