本文整理汇总了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);
}));
示例2: done
writable._write = (input, encoding, done) => {
if (readable.push(input)) {
done();
} else {
readable.once('drain', done as (...args: any[]) => void);
}
};
示例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);
}
};
});
示例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);
}));
示例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);
}
}));
示例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();
});
}
示例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();
}
});