read-webfile
read a file from a url just like from a file path!
Installation
npm i web-file --save
wf.readFileFromWeb(path[, options], callback)
basicly, this function is design to follow native API of fs.readFile.
const wf = require('web-file')
let url = 'https://nodejs.org/en/'
wf.readFileFromWeb(url, 'utf8', (err, data) => {
if(err) console.error(err)
console.log(data)
})
wf.createReadStream(path[, options])
basicly, this function is design to follow native API of fs.createReadStream.
- path
<string> | <URL>
- options
<string> | <Object>
- encoding
<string> Default: null
- Returns: a Readable Stream.
const wf = require('web-file')
let url = 'https://nodejs.org/en/'
const rs = wf.createReadStreamFromWeb(url)
rs.on('data', chunk => {
console.log(chunk.toString('utf8'))
})
rs1.on('end', () => {
console.log('onend')
})