• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript https.get函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中https.get函数的典型用法代码示例。如果您正苦于以下问题:TypeScript get函数的具体用法?TypeScript get怎么用?TypeScript get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: download

 return new Promise<stream.Readable>((resolve, reject) => {
     return https.get(options, res => {
         // handle redirection
         if (res.statusCode === 302) {
             return download(res.headers.location);
         }
         else if (res.statusCode !== 200) {
             return reject(Error(`Download failed with code ${res.statusCode}.`));
         }
         
         return resolve(res);
     });
 });
开发者ID:J1978,项目名称:omnisharp-vscode,代码行数:13,代码来源:omnisharpDownload.ts


示例2: res

 return new Promise<void>((res, rej) => {
     let file = fs.createWriteStream(f);
     file.on("close", () => {
         console.log("Downloaded " + f);
         res();
     });
     https.get(consts.base_url + f, (r) => {
         r.pipe(file);
     }).on("error", (e: any) => {
         console.log("Failed to download " + f);
         rej(e);
     });
 });
开发者ID:Ronmi,项目名称:react-boilerplate,代码行数:13,代码来源:utils.ts


示例3: downloadJDK

/**
 * Downloads the JDK at JDK_URL into the destination path.
 * Creates the path if it doesn't exist.
 */
function downloadJDK(url: string, destPath: string, cb: (err?: Error) => void) {
  let ended = false;
  mkdirp(destPath);
  https.get(url, (res) => {
    if (res.statusCode === 302) {
      // Redirected.
      ended = true;
      downloadJDK(res.headers['location'], destPath, cb);
      return;
    }

    // Will be NaN if not given by server.
    let contentLength = parseInt(res.headers['content-length']);
    let progressBytes = 0;
    let startTime = new Date().getTime();

    function printStatus() {
      let percent = "??";
      if (!isNaN(contentLength)) {
        percent = ((progressBytes/contentLength)*100).toFixed(0);
      }
      let lastPrint = new Date().getTime();
      // bytes => kbytes
      let dlSoFar = progressBytes >> 10;
      let rate = dlSoFar / ((lastPrint - startTime) / 1000);
      console.log(`[${percent}%] Received ${dlSoFar} KB [${rate.toFixed(2)} KB/s]`);
    }

    let interval = setInterval(function() {
      printStatus();
    }, 5000);

    function end(err?: Error) {
      if (!ended) {
        ended = true;
        clearInterval(interval);
        cb(err);
      }
    }

    res.pipe(gunzip()).pipe(tarFs.extract(destPath)).on('error', end).on('finish', end);
    res.on('data', (d: Buffer) => {
      progressBytes += d.length;
    });
  }).on('error', (err: Error) => {
    if (!ended) {
      ended = true;
      cb(err);
    }
  });
}
开发者ID:plasma-umass,项目名称:doppio,代码行数:55,代码来源:download_jdk.ts


示例4: Promise

 return new Promise((resolve, reject) => {
   get(url, (res) => {
     let body = '';
     res.on('data', (data) => body = body + data);
     res.on('error', (err) => console.log(err));
     res.on('end', () => {
       if (IGNORED_CONTENTS.some((content) => body === content)) {
         resolve();
       } else {
         outputFileAsync(outputPath, body).then(() => resolve()).catch(reject);
       }
     });
   }).on('error', reject);
 });
开发者ID:Mercateo,项目名称:typedocs,代码行数:14,代码来源:i18n-import.ts


示例5: resolve

const httpsGet = (url: string) => new Promise<string>((resolve, reject) => {
    https.get(url, res => {
        const frames: Buffer[] = [];
        res.on("data", (data: Buffer) => {
            frames.push(data);
        });
        res.on("end", () => {
            resolve(Buffer.concat(frames).toString("utf8"));
        });
        res.on("error", (err: Error) => {
            reject(err);
        });
    });
});
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:14,代码来源:index.ts


示例6: resolve

    return new Promise<string>( (resolve, reject) => {
        let fileName = prefix + requestTimestamp + "." + extension;
        let filePath = config.get("save_path") + fileName;
        let file = fs.createWriteStream(filePath);


        https.get(url, (metaResponse: any) => {
            metaResponse.pipe(file);

            metaResponse.on('end', () => {
               resolve(fileName); 
            });
        });   
    });
开发者ID:usa-npn,项目名称:pop-service,代码行数:14,代码来源:server.ts


示例7: function

    users.forEach(element => {

        var user = db.default.getUserByName(element);
        if (user) {
            options.headers["if-none-match"] = user.etag;
        } else {
            user = { name: element, languages: [], etag: null };
        }

        options.path = `/users/${element}/repos?access_token=${config.Config.access_token}`;

        var req = https.get(options, function(res) {
            onResponse(res, user);
        }).on("error", handleRequestError);
    });
开发者ID:SFWLtd,项目名称:govuk-github-caller,代码行数:15,代码来源:request.ts


示例8: ensureDirectoryExistence

const downloadFile = (status: string, filePath: string, url: string) => {
  ensureDirectoryExistence(filePath);
  const file = fs.createWriteStream(filePath);

  https.get(url, (response: any) => {
    response.pipe(file);

    file.on('finish', () => {
      file.close();
      console.info(`${status}: ${filePath}`);
    });
  }).on('error', () => {
    deleteFile(status, filePath);
  });
};
开发者ID:trungx,项目名称:vue-starter,代码行数:15,代码来源:update.ts


示例9: Promise

  return new Promise((resolve, reject) => {
    get(format(url), response => {
      let body = '';
      response.setEncoding('utf8');
      response.on('data', chunk => body += chunk);
      response.on('end', () => {
        if (response.statusCode !== 200) {
          reject(new Error(`unable to get latest version (code=${response.statusCode}): ${body}`));
        }

        let packageInfo = JSON.parse(body);
        resolve(packageInfo['dist-tags']['latest']);
      });
    }).on('error', reject);
  });
开发者ID:alangpierce,项目名称:decaffeinate,代码行数:15,代码来源:getLatestVersion.ts


示例10:

 return Observable.create<string>((subscriber) => { 
     var urlRawData:string = "";
     
     https.get({ 
         host: host,
         path: dirPath
     }, (response) => {
         response.on('data', (chunk) => urlRawData += chunk)
         
         response.on('end', () => {
             subscriber.onNext(urlRawData);
             subscriber.onCompleted();
         });
     });
 });
开发者ID:creativedrewy,项目名称:creativedrewy.com,代码行数:15,代码来源:RawGetDataServiceBase.ts



注:本文中的https.get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript https.request函数代码示例发布时间:2022-05-25
下一篇:
TypeScript https.createServer函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap