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


TypeScript Readable.once方法代码示例

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


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

示例1: mkdirp

	return mkdirp(targetDirName).then(() => new TPromise((c, e) => {
		let istream = createWriteStream(targetFileName, { mode });
		istream.once('finish', () => c(null));
		istream.once('error', e);
		stream.once('error', e);
		stream.pipe(istream);
	}));
开发者ID:AlexxNica,项目名称:sqlopsstudio,代码行数:7,代码来源:zip.ts

示例2: done

writable._write = (input, encoding, done) => {
    if (readable.push(input)) {
        done();
    } else {
        readable.once('drain', done as (...args: any[]) => void);
    }
};
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:7,代码来源:duplexer3-tests.ts

示例3: Promise

    const p = new Promise((resolve, reject) => {
        const error = (err: any) => {
            if (err) {
                // null check
                err.bufferedData = stream.getBufferedValue();
            }

            reject(err);
        };

        stream = bufferStream(opts);
        inputStream.once("error", error);
        inputStream.pipe(stream);

        stream.on("data", () => {
            if (stream.getBufferedLength() > maxBuffer) {
                reject(new Error("maxBuffer exceeded"));
            }
        });
        stream.once("error", error);
        stream.on("end", resolve);

        clean = () => {
            // some streams doesn't implement the `stream.Readable` interface correctly
            if (inputStream.unpipe) {
                inputStream.unpipe(stream);
            }
        };
    });
开发者ID:nrkn,项目名称:quicktype,代码行数:29,代码来源:index.ts

示例4: mkdirp

	return mkdirp(targetDirName, void 0, token).then(() => new TPromise((c, e) => {
		if (token.isCancellationRequested) {
			return;
		}

		istream = createWriteStream(targetFileName, { mode });
		istream.once('close', () => c(null));
		istream.once('error', e);
		stream.once('error', e);
		stream.pipe(istream);
	}));
开发者ID:developers23,项目名称:vscode,代码行数:11,代码来源:zip.ts

示例5: createWriteStream

	return Promise.resolve(mkdirp(targetDirName, undefined, token)).then(() => new Promise<void>((c, e) => {
		if (token.isCancellationRequested) {
			return;
		}

		try {
			istream = createWriteStream(targetFileName, { mode });
			istream.once('close', () => c());
			istream.once('error', e);
			stream.once('error', e);
			stream.pipe(istream);
		} catch (error) {
			e(error);
		}
	}));
开发者ID:joelday,项目名称:vscode,代码行数:15,代码来源:zip.ts

示例6: onData

function onData(stream: Readable, session: SMTPServerSession, callback: (err?: Error) => void): void {
    console.log(`[${session.id}] onData started`);

    let messageLength = 0;

    stream.on('data', (chunk: Buffer) => {
        console.log(`[${session.id}] onData got data chunk ${chunk.length} bytes`);
        messageLength += chunk.length;
    });

    stream.once('end', () => {
        console.log(`[${session.id}] onData finished after reading ${messageLength} bytes`);
        callback();
    });
}
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:15,代码来源:smtp-server-tests.ts

示例7: function

  t.test("once handler registered out of context on Readable", function (t) {
    var Readable = require('stream').Readable;

    if (Readable) {
      t.plan(12);

      var n  = cls.createNamespace('outOnceReadable')
        , re = new Readable()
        ;

      re._read = function () {};

      t.ok(n.name, "namespace has a name");
      t.equal(n.name, 'outOnceReadable', "namespace has a name");

      re.once('data', function (data: any) {
        t.equal(n.get('value'), 'hello', "value still set in EE");
        t.equal(data, 'blah', "emit still works");
        cls.destroyNamespace('outOnceReadable');
      });

      n.run(function () {
        n.set('value', 'hello');

        t.notOk(re.emit.__wrapped, "emit is not wrapped");
        t.notOk(re.on.__wrapped, "on is not wrapped");
        t.notOk(re.addListener.__wrapped, "addListener is not wrapped");

        n.bindEmitter(re);

        t.ok(re.emit.__wrapped, "emit is wrapped");
        t.ok(re.on.__wrapped, "on is wrapped");
        t.ok(re.addListener.__wrapped, "addListener is wrapped");

        t.equal(typeof re._events.data, 'function', 'only the one data listener');
        t.notOk(re._events.data['context@outOnceReadable'], "context isn't on listener");

        re.emit('data', 'blah');
      });
    }
    else {
      t.comment("this test requires node 0.10+");
      t.end();
    }
  });
开发者ID:ArtemZag,项目名称:DefinitelyTyped,代码行数:45,代码来源:continuation-local-storage-tests.ts


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