本文整理匯總了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);
});