UNPKG

579 BJavaScriptView Raw
1import fileFetch from 'file-fetch'
2import httpFetch from 'nodeify-fetch'
3import protoFetch from '../index.js'
4
5const fetch = protoFetch({
6 [null]: fileFetch,
7 file: fileFetch,
8 http: httpFetch,
9 https: httpFetch
10})
11
12async function contentLength (url) {
13 const length = (await (await fetch(url)).text()).length
14
15 console.log(`content length of ${url}: ${length}`)
16}
17
18await contentLength('package.json')
19await contentLength('file:package.json')
20await contentLength(`file://${process.cwd()}/package.json`)
21await contentLength('https://www.unpkg.com/proto-fetch/package.json')