ledown
Version:
A library for nodejs to download http large file in pauseable and resumable way
18 lines (16 loc) • 427 B
JavaScript
import { request, type IncomingMessage } from 'http'
import { parse } from 'url'
export default function fetch (url, options): Promise<IncomingMessage> {
return new Promise((resolve, reject) => {
const { path, port, protocol, hostname } = parse(url)
const req = request({
...options,
port,
hostname,
protocol,
path: path
}, resolve)
req.on('error', reject)
req.end()
})
}