本文整理汇总了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);
});
}
})
开发者ID:driftyco,项目名称:ionic-cli,代码行数:33,代码来源:resources.ts
示例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');
});
开发者ID:driftyco,项目名称:ionic-cli,代码行数:8,代码来源:logger.ts
示例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');
});
});
开发者ID:driftyco,项目名称:ionic-cli,代码行数:16,代码来源:logger.ts
注:本文中的@ionic/utils-stream.WritableStreamBuffer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论