本文整理匯總了TypeScript中@ionic/utils-stream.WritableStreamBuffer類的典型用法代碼示例。如果您正苦於以下問題:TypeScript WritableStreamBuffer類的具體用法?TypeScript WritableStreamBuffer怎麽用?TypeScript WritableStreamBuffer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了WritableStreamBuffer類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: debug
.on('response', res => {
debug('response %d received for %s: (id: %s)', res.statusCode, resource.name, resource.imageId);
if (res.statusCode !== 200) {
const generalErrorMsg = !res.statusCode || res.statusCode >= 500
? 'the server may be experiencing difficulties right now--please try again later.'
: 'the server marked a source image as invalid for this resource.';
errorMarker = true;
const buf = new WritableStreamBuffer();
res.pipe(buf);
buf.on('finish', () => {
let serverMsg = buf.consume().toString();
try {
serverMsg = JSON.parse(serverMsg).Error;
} catch (e) {
serverMsg = formatResponseError(req, res.statusCode, serverMsg);
}
result.error = new Error(
`Error while generating ${strong(resource.name)}: ` +
`${generalErrorMsg}\n\n` +
`Server: "${serverMsg}"`
);
resolve(result);
});
}
})
示例2: it
it('should create a writable stream', () => {
const stream = new WritableStreamBuffer();
const handler = new StreamHandler({ stream });
const logger = new Logger({ handlers: new Set([handler]) });
const ws = logger.createWriteStream();
ws.write('hi');
expect(stream.consume().toString()).toEqual('hi\n');
});
示例3: describe
describe('msg', () => {
let stream: WritableStreamBuffer;
let logger: Logger;
beforeEach(() => {
stream = new WritableStreamBuffer();
logger = new Logger({ handlers: new Set([new StreamHandler({ stream })]) });
});
it('should write the message directly', () => {
logger.msg('hi');
expect(stream.consume().toString()).toEqual('hi\n');
});
});