-
-
Save OMGZui/8cf0b430314715cf917094d8bc12eabe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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