downloader.ts 581 B

12345678910111213141516171819202122232425
  1. import { debug } from '../lib/logger'
  2. import request from '../lib/request'
  3. import { writeFile } from '../lib/util'
  4. class Downloader {
  5. public static create() {
  6. return new Downloader()
  7. }
  8. private constructor() {}
  9. public async download(downloadUrl: string, savedPath: string) {
  10. debug('Downloading the mkcert executable from %s', downloadUrl)
  11. const { data } = await request.get(downloadUrl, {
  12. responseType: 'arraybuffer'
  13. })
  14. await writeFile(savedPath, data)
  15. debug('The mkcert has been saved to %s', savedPath)
  16. }
  17. }
  18. export default Downloader