Created
July 7, 2021 20:09
-
-
Save maggiben/e8508d3b7fe3ef4c5e01b82319eccfb5 to your computer and use it in GitHub Desktop.
Read URL (transform stream -> promise)
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
| private readUrl(url: string): Promise < string > { | |
| return new Promise((resolve, reject) => { | |
| https.get(url, (response) => { | |
| response.setEncoding('utf8'); | |
| let body = ''; | |
| response.on('data', (data) => { | |
| body += data; | |
| }); | |
| response.on('end', () => { | |
| resolve(body); | |
| }); | |
| response.on('error', (error) => { | |
| reject(error); | |
| }); | |
| }); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment