當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。