Skip to content

Instantly share code, notes, and snippets.

@OMGZui
Created November 18, 2022 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OMGZui/8cf0b430314715cf917094d8bc12eabe to your computer and use it in GitHub Desktop.
Save OMGZui/8cf0b430314715cf917094d8bc12eabe to your computer and use it in GitHub Desktop.
interface Idownload {
(path: string): Promise<string>
}
export let download: Idownload
download = (path: string) => {
const header = new Url.URL(path)
return new Promise((resolve, reject) => {
const req = Https.request(header, res => {
let content = ''
res.setEncoding('binary')
res.on('data', data => (content += data))
res.on('end', () => resolve(content))
})
req.on('error', err => reject(err))
req.end()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment