本文整理汇总了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();
});
});
示例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();
});
});
示例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());
});
示例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;
}
}
示例5: stream
export function stream(url: string, headers: any): NodeJS.ReadableStream {
headers["User-Agent"] = userAgent;
return got.stream(url, { headers });
}