当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript stream.PassThrough类代码示例

本文整理汇总了TypeScript中stream.PassThrough的典型用法代码示例。如果您正苦于以下问题:TypeScript PassThrough类的具体用法?TypeScript PassThrough怎么用?TypeScript PassThrough使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了PassThrough类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

    it('should be doubly pipeable', done => {
      const wsb = new WritableStreamBuffer();
      const rs1 = new PassThrough();
      const rs2 = new PassThrough();
      rs1.pipe(wsb);
      rs2.pipe(wsb);

      const i1 = setInterval(() => { rs1.write('a') }, 100);
      const i2 = setInterval(() => { rs2.write('b') }, 150);

      setTimeout(() => {
        clearInterval(i1);
        rs1.end();
      }, 2000);

      setTimeout(() => {
        clearInterval(i2);
        rs2.end();
      }, 3000);

      jest.advanceTimersByTime(3000);

      wsb.on('finish', () => {
        const result = wsb.consume();
        expect(result.toString()).toEqual(expect.stringMatching(/[ab]{40}/));
        done();
      });
    });
开发者ID:driftyco,项目名称:ionic-cli,代码行数:28,代码来源:index.ts

示例2: rp

    rp(options).then(response => {

      const stream = require('stream');
      const bufferStream = new stream.PassThrough();

      bufferStream.end(Buffer.from(response.body, 'base64'));

      const file = admin.storage().bucket().file('name.jpg');

      bufferStream.pipe(
        file.createWriteStream({
          public: true
        }))
        .on('error', function(error) {
          console.log(error);
          return res.status(500).send(error);
        })
        .on('finish', function() {

          const config: GetSignedUrlConfig = {
            action: 'read',
            expires: '01-01-2025'
          };
          file.getSignedUrl(config, function(error, url) {
            console.log(url);
            if (error) {
              return res.status(500).send(error);
            }
            return res.status(500).send(url);
          });

        });

      res.send('Success');
    })
开发者ID:Meistercoach83,项目名称:sfw,代码行数:35,代码来源:get-unsplash-item.ts

示例3: as

(async () => {

    const sources = argv.help ? [] : [
        ...files.map((file) => () => fs.createReadStream(file)),
        ...(process.stdin.isTTY ? [] : [() => process.stdin])
    ].filter(Boolean) as (() => NodeJS.ReadableStream)[];

    let reader: RecordBatchReader | null;
    let hasReaders = false;

    for (const source of sources) {
        if (state.closed) { break; }
        for await (reader of recordBatchReaders(source)) {
            hasReaders = true;
            const source = reader.toNodeStream();
            const xform = batchesToString(state, reader.schema);
            const sink = new stream.PassThrough();
            sink.pipe(process.stdout, { end: false });
            await pipeline(source, xform, sink).catch(() => state.closed = true);
        }
        if (state.closed) { break; }
    }

    return hasReaders ? 0 : print_usage();
})()
开发者ID:laurentgo,项目名称:arrow,代码行数:25,代码来源:arrow2csv.ts

示例4: test

test('it should change the stderr stream', t => {
  const streamStore = streamStoreFactory(initMockStreams())
  const stderr = new PassThrough
  streamStore.setStream({stderr})
  streamStore.get('stderr').write('apple')
  t.is(stderr.read().toString(), 'apple')
})
开发者ID:lab-coop,项目名称:lab-stdio,代码行数:7,代码来源:stream-store.spec.ts

示例5: async

async () => {
    const s = new PassThrough();
    s.write('howdy');
    s.end();
    const { stdout } = await execa('stdin', { input: s });
    assert(stdout === 'foobar');
};
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:7,代码来源:execa-tests.ts

示例6: it

    it('DeleteLayer Test -', (done: () => void) => {
		var response = new PassThrough();
		response.write(JSON.stringify({'statusCode': '202'}));        
		response.end();
        var req = new PassThrough();
        this.request.callsArgWith(1,response).returns(req);
        wrapper.deleteLayer('name','digest',(err)=>{  
            done();
        });
    });
开发者ID:beverts312,项目名称:docker-registry-cli,代码行数:10,代码来源:registry-wrapper-tests.ts

示例7: it

 it('produces multiple chunks from a fed stream', () => {
   const str = new stream.PassThrough({highWaterMark: 1024});
   const src = Source.fromInputStream(() => str);
   const data1 = new Buffer(1024);
   const data2 = new Buffer(1024);
   str.write(data1);
   str.write(data2);
   str.end();
   return chai.expect(src.toArray()).to.eventually.deep.equal([data1, data2]);
 });
开发者ID:srijs,项目名称:node-pacific,代码行数:10,代码来源:source-spec.ts

示例8: Error

 (res: http.IncomingMessage) => {
   if (res.statusCode === 200) {
     res.pipe(fileStream);
     return;
   }
   fileStream.emit('error', new Error(STATUS_CODES[res.statusCode]));
   fileStream.emit('end');
 },
开发者ID:kingsquare,项目名称:communibase-connector-js,代码行数:8,代码来源:index.ts

示例9: setInterval

	const interval = setInterval(() => {
		if (count++ < 10) {
			slowStream.push('data\n'.repeat(100));
			return;
		}

		clearInterval(interval);
		slowStream.push(null);
	}, 100);
开发者ID:sindresorhus,项目名称:got,代码行数:9,代码来源:slow-data-stream.ts


注:本文中的stream.PassThrough类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。