当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript got.stream函数代码示例

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


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

示例1:

test.cb('have response event', (t) => {
    got.stream(s.url)
        .on('response', res => {
            t.is(res.statusCode, 200);
            t.end();
        });
});
开发者ID:cyounkins,项目名称:typed-got,代码行数:7,代码来源:stream.ts

示例2: intoStream

test.cb('accepts option.body as Stream', (t) => {
    got.stream(`${s.url}/post`, {body: intoStream(['wow'])})
        .on('data', chunk => {
            t.is(chunk.toString(), 'wow');
            t.end();
        });
});
开发者ID:cyounkins,项目名称:typed-got,代码行数:7,代码来源:stream.ts

示例3: Promise

    await new Promise((resolve, reject) => {
      const downloadStream = got.stream(url);
      downloadStream.pipe(writeStream);

      downloadStream.on('error', error => reject(error));
      writeStream.on('error', error => reject(error));
      writeStream.on('close', () => resolve());
    });
开发者ID:electron-userland,项目名称:electron-download,代码行数:8,代码来源:GotDownloader.ts

示例4: downloadUpdate

export async function downloadUpdate(
  fileName: string,
  logger: LoggerType
): Promise<string> {
  const baseUrl = getUpdatesBase();
  const updateFileUrl = `${baseUrl}/${fileName}`;

  const signatureFileName = getSignatureFileName(fileName);
  const signatureUrl = `${baseUrl}/${signatureFileName}`;

  let tempDir;
  try {
    tempDir = await createTempDir();
    const targetUpdatePath = join(tempDir, fileName);
    const targetSignaturePath = join(tempDir, getSignatureFileName(fileName));

    logger.info(`downloadUpdate: Downloading ${signatureUrl}`);
    const { body } = await get(signatureUrl, getGotOptions());
    await writeFile(targetSignaturePath, body);

    logger.info(`downloadUpdate: Downloading ${updateFileUrl}`);
    const downloadStream = stream(updateFileUrl, getGotOptions());
    const writeStream = createWriteStream(targetUpdatePath);

    await new Promise((resolve, reject) => {
      downloadStream.on('error', error => {
        reject(error);
      });
      downloadStream.on('end', () => {
        resolve();
      });

      writeStream.on('error', error => {
        reject(error);
      });

      downloadStream.pipe(writeStream);
    });

    return targetUpdatePath;
  } catch (error) {
    if (tempDir) {
      await deleteTempDir(tempDir);
    }
    throw error;
  }
}
开发者ID:WhisperSystems,项目名称:Signal-Desktop,代码行数:47,代码来源:common.ts

示例5: stream

export function stream(url: string, headers: any): NodeJS.ReadableStream {
  headers["User-Agent"] = userAgent;
  return got.stream(url, { headers });
}
开发者ID:eggyo,项目名称:dang-ai,代码行数:4,代码来源:http.ts


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