read-webfile

0.2.1 • Public • Published

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
  • 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>
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
  • 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.

Package Sidebar

Install

npm i read-webfile

Weekly Downloads

0

Version

0.2.1

License

MIT

Unpacked Size

10.9 kB

Total Files

10

Last publish

Collaborators

  • saltfish666