read-webfile
v0.2.1
Published
let you readFile from web just like fs.readFile
Downloads
1
Maintainers
Readme
read-webfile
read a file from a url just like from a file path!
Installation
npm i read-webfile --save
wf.readFileFromWeb(path[, options], callback)
basicly, this function is design to follow native API of fs.readFile.
path
<string>
|<URL>
required- can be a string such as
https://nodejs.org
- can be a URL object such as
new URL('https://nodejs.org')
- is required, and only support http or https portocol
- can be a string such as
options
<Object>
|<string>
- can be a string which represent encoding such as 'utf8'
- can be object such as
{encoding: 'utf8'}
callback
<Function>
- err
<Error>
- data
<string>
|<Buffer>
- err
const wf = require('read-webfile')
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
- encoding
- Returns: a Readable Stream.
const wf = require('read-webfile')
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')
})
notice
this function can not handler redirect such a http 304 code.