本文整理汇总了TypeScript中get-stream.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('has redirect event', withServer, async (t, server, got) => {
server.get('/', defaultHandler);
server.get('/redirect', redirectHandler);
const stream = got.stream('redirect');
const {headers} = await pEvent(stream, 'redirect');
t.is(headers.location, '/');
await getStream(stream);
});
示例2: getStream
test('`isFromCache` stream property is true if the response was cached', withServer, async (t, server, got) => {
server.get('/', cacheEndpoint);
const cache = new Map();
await getStream(got.stream({cache}));
const stream = got.stream({cache});
const response = await pEvent(stream, 'response') as Response;
t.is(response.isFromCache, true);
t.is(stream.isFromCache, true);
await getStream(stream);
});
示例3: async
let doOcpIndent = async (code: string, token: vscode.CancellationToken) => {
let ocpIndentPath = configuration.get<string>('ocpIndentPath');
let cp = child_process.spawn(ocpIndentPath, ['--numeric']);
token.onCancellationRequested(() => {
cp.disconnect();
});
cp.stdin.write(code);
cp.stdin.end();
let output = await getStream(cp.stdout);
cp.unref();
if (token.isCancellationRequested) return null;
let newIndents = output.trim().split(/\n/g).map((n) => +n);
let oldIndents = code.split(/\n/g).map((line) => /^\s*/.exec(line)[0]);
let edits = [];
newIndents.forEach((indent, line) => {
let oldIndent = oldIndents[line];
let newIndent = ' '.repeat(indent);
if (oldIndent !== newIndent) {
edits.push(vscode.TextEdit.replace(
new vscode.Range(
new vscode.Position(line, 0),
new vscode.Position(line, oldIndent.length)
),
newIndent)
);
}
});
return edits;
};
示例4: async
test('decompress content - stream', withServer, async (t, server, got) => {
server.get('/', (_request, response) => {
response.setHeader('Content-Encoding', 'gzip');
response.end(gzipData);
});
t.is((await getStream(got.stream(''))), testContent);
});
示例5: async
test('returns writeable stream', withServer, async (t, server, got) => {
server.post('/', postHandler);
const stream = got.stream.post('');
const promise = getStream(stream);
stream.end('wow');
t.is(await promise, 'wow');
});
示例6: incomplete
test('throws on incomplete (canceled) response - stream', withServer, async (t, server, got) => {
server.get('/', downloadHandler);
const errorString = 'Foobar';
const stream = got.stream('').on('response', () => {
setTimeout(() => stream.destroy(new Error(errorString)), 500);
});
await t.throwsAsync(getStream(stream), errorString);
});
示例7: async
test('rewrites /node_modules references, 1 dir nested', async (t) => {
const filePath = '/demo/index.html';
const beforeStream = new Readable();
beforeStream.push('<script src="../node_modules/other-package/file.html">');
beforeStream.push(null);
beforeStream.setEncoding('utf8');
const expected = '<script src="/other-package/file.html">';
const actualStream = beforeStream.pipe(new HTMLRewriter({}, filePath));
t.is(await getStream(actualStream), expected);
});