當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript utils-stream.WritableStreamBuffer類代碼示例

本文整理匯總了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;未經允許,請勿轉載。