本文整理汇总了TypeScript中stream.Duplex.push方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Duplex.push方法的具体用法?TypeScript Duplex.push怎么用?TypeScript Duplex.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stream.Duplex
的用法示例。
在下文中一共展示了Duplex.push方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
client.on('message', function(data) {
log.debug('c->s ', JSON.stringify(data));
if (data['a']=='sub' || data['a']=='bs') {
if (data['a']=='sub') {
// User is subscribing to a new document
log.debug("Got new sub");
document = data['d'];
} else { // data['a']=='bs'
var collectionDocumentVersionMap = data['s'];
var numCollections = Object.keys(collectionDocumentVersionMap).length;
if (numCollections != 1) {
log.error({message:"Zero or more than one collection not expected",value:numCollections});
client.stop();
return;
}
var cName = Object.keys(collectionDocumentVersionMap)[0];
var numDocuments = Object.keys(collectionDocumentVersionMap[cName]).length;
if (numDocuments != 1) {
log.error({message:"Zero or more than one document not expected",value:numDocuments});
client.stop();
return;
}
var docName = Object.keys(collectionDocumentVersionMap[cName])[0];
document = docName;
}
mongoStore.get(sessionId, function(err, session) {
if (err) {
log.error(err);
client.stop();
return;
}
if (!session) {
log.error({message:"Tried to get session that doesn't exist",value:rawSessionCookie});
client.stop();
return;
}
var userId = session.passport.user;
if (!userId) {
log.error({message:"Tried to get userId that doesn't exist",value:session});
client.stop();
return;
}
AuthHelper.userIdCanAccessPageId(userId, document, function(canAccess) {
if (!canAccess) {
client.stop();
return;
}
pageConnectionMap[document] = pageConnectionMap[document] ?
pageConnectionMap[document]+1 :
1;
log.info(pageConnectionMap[document] + " CLIENTS CONNECTED TO " + document);
stream.push(data);
});
});
} else {
stream.push(data);
}
});
示例2: bufferToStream
export function bufferToStream(buffer: Buffer) {
const stream = new Duplex()
stream.push(buffer)
stream.push(null)
return stream
}