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


TypeScript PassThrough.pipe方法代码示例

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


在下文中一共展示了PassThrough.pipe方法的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: it

  it('can be serialised over a stream', async () => {
    const outgoingMessages: Wrapper[] = createOutgoingMessages()

    const out = new PassThrough()
    const input = out.pipe(new ProtobufMessageStream(Wrapper.decodeDelimited.bind(Wrapper)))

    writeOutgoingMessages(outgoingMessages, out)
    const incomingMessages: Wrapper[] = await readIncomingMessages(input)

    assert.deepStrictEqual(incomingMessages, outgoingMessages)
  })
开发者ID:cucumber,项目名称:cucumber,代码行数:11,代码来源:message_serialization_test.ts

示例5: it

 it('should process x-www-form-urlencoded with gzip encoding', async function () {
   const req = new PassThrough();
   const stream = req.pipe(createGzip());
   (stream as any).headers = {
     'content-type': 'application/x-www-form-urlencoded',
     'content-encoding': 'gzip',
     'content-length': 29
   };
   (stream as any).method = 'GET';
   (stream as any).url = '/upload';
   req.end('name=thatiq&key=value&abc=xyz');
   const ctx = W.createHttpContext(stream as any);
   await T.toPromise(middleware(simpleApp)(ctx, T.pure));
   assert.deepEqual(ctx.state.body, {
     name: 'thatiq',
     key: 'value',
     abc: 'xyz'
   });
 });
开发者ID:syaiful6,项目名称:jonggrang,代码行数:19,代码来源:form-fields.ts

示例6: async

export const extractArchive = async (archive: Buffer, destination: string): Promise<string[]> => {
  try {
    if (!fse.existsSync(destination)) {
      fse.mkdirSync(destination)
    }
    const buffStream = new stream.PassThrough()
    const tarWriteStream = tar.x({ sync: true, strict: true, cwd: destination })

    buffStream.end(archive)
    buffStream.pipe(tarWriteStream)

    await new Promise((resolve, reject) => {
      tarWriteStream.on('end', resolve)
      tarWriteStream.on('error', reject)
    })

    const files = await Promise.fromCallback<string[]>(cb => glob('**/*.*', { cwd: destination }, cb))
    return files.map(filePath => forceForwardSlashes(filePath))
  } catch (err) {
    throw new VError(err, `[Archive] Error extracting archive to "${destination}"`)
  }
}
开发者ID:alexsandrocruz,项目名称:botpress,代码行数:22,代码来源:archive.ts

示例7: PassThrough

import { PassThrough } from 'stream';
import ReadlineTransform from 'readline-transform';

const readStream = new PassThrough();
const transform = new ReadlineTransform({
  breakMatcher: /\n/,
  ignoreEndOfBreak: false,
  skipEmpty: true
});
const writeStream = new PassThrough({ objectMode: true });

readStream.pipe(transform).pipe(writeStream);
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:12,代码来源:readline-transform-tests.ts

示例8:

 .then(zip => {
     var buffer = zip.generate({ type: "nodebuffer" });
     var bufferStream = new stream.PassThrough();
     bufferStream.end( buffer );
     bufferStream.pipe(unzip.Extract({ path: `${vscode.workspace.rootPath}/src` }));
 });
开发者ID:rebornix,项目名称:ForceCode,代码行数:6,代码来源:retrieve.ts

示例9: Promise

        return new Promise((resolve, reject) => {
          const arg: any = urlLib.parse(url)
          const isHttp = arg.protocol !== 'https:'
          const engine: typeof httpRequest = isHttp ? httpRequest : httpsRequest

          // Always attach certain options.
          arg.method = method
          arg.headers = request.toHeaders()
          arg.agent = options.agent
          arg.rejectUnauthorized = options.rejectUnauthorized !== false
          arg.ca = options.ca
          arg.cert = options.cert
          arg.key = options.key

          const req = engine(arg)

          // Track upload progress through a stream.
          const requestProxy = new PassThrough()
          const responseProxy = new PassThrough()

          requestProxy.on('data', function (chunk: Buffer) {
            request.uploadedBytes = request.uploadedBytes + chunk.length
          })

          requestProxy.on('end', function () {
            request.uploadedBytes = request.uploadLength
          })

          responseProxy.on('data', function (chunk: Buffer) {
            request.downloadedBytes = request.downloadedBytes + chunk.length
          })

          responseProxy.on('end', function () {
            request.downloadedBytes = request.downloadLength
          })

          // Handle the HTTP response.
          function response (res: IncomingMessage) {
            const status = res.statusCode
            const redirect = REDIRECT_STATUS[status]

            // Handle HTTP redirects.
            if (followRedirects && redirect != null && res.headers.location) {
              const newUrl = urlLib.resolve(url, res.headers.location)

              // Ignore the result of the response on redirect.
              res.resume()

              // Kill the old cookies on redirect.
              request.remove('Cookie')

              if (redirect === REDIRECT_TYPE.FOLLOW_WITH_GET) {
                // Update the "Content-Length" for updated redirection body.
                request.set('Content-Length', '0')

                return get(newUrl, 'GET')
              }

              if (redirect === REDIRECT_TYPE.FOLLOW_WITH_CONFIRMATION) {
                // Following HTTP spec by automatically redirecting with GET/HEAD.
                if (arg.method === 'GET' || arg.method === 'HEAD') {
                  return get(newUrl, method, body)
                }

                // Allow the user to confirm redirect according to HTTP spec.
                if (confirmRedirect(req, res)) {
                  return get(newUrl, method, body)
                }
              }
            }

            request.downloadLength = num(res.headers['content-length'], 0)

            // Track download progress.
            res.pipe(responseProxy)

            return Promise.resolve({
              body: responseProxy,
              status: status,
              statusText: res.statusMessage,
              headers: res.headers,
              rawHeaders: res.rawHeaders,
              url: url
            })
          }

          // Handle the response.
          req.once('response', function (message: IncomingMessage) {
            return resolve(setCookies(request, message).then(() => response(message)))
          })

          // io.js has an abort event instead of "error".
          req.once('abort', function () {
            return reject(request.error('Request aborted', 'EABORT'))
          })

          req.once('error', function (error: Error) {
            return reject(request.error(`Unable to connect to "${url}"`, 'EUNAVAILABLE', error))
          })

//.........这里部分代码省略.........
开发者ID:garethhunt,项目名称:popsicle,代码行数:101,代码来源:index.ts


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