本文整理汇总了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');
});
});