本文整理匯總了TypeScript中levelup.LevelUp.createReadStream方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript LevelUp.createReadStream方法的具體用法?TypeScript LevelUp.createReadStream怎麽用?TypeScript LevelUp.createReadStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類levelup.LevelUp
的用法示例。
在下文中一共展示了LevelUp.createReadStream方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: get
public get(query: any, callback: (data: any) => void) {
if (query === null) {
const result: any = {};
this.db
.createReadStream()
.on('data', (data: any) => {
result[data.key] = data.value;
})
.on('end', () => {
callback(result);
});
} else if (Array.isArray(query)) {
const result: any = {};
this.db
.createReadStream()
.on('data', (data: any) => {
for (const key of query) {
if (key === data.key) {
result[data.key] = data.value;
}
}
})
.on('end', () => {
callback(result);
});
} else if (typeof query === 'object') {
const result: any = { ...query };
this.db
.createReadStream()
.on('data', (data: any) => {
for (const key in query) {
if (key === data.key && data.value !== undefined) {
result[data.key] = data.value;
}
}
})
.on('end', () => {
callback(result);
});
} else if (typeof query === 'string') {
this.db.get(query, (err, value) => {
if (err) {
if (err.notFound) {
return callback({});
}
}
callback({ [query]: value });
});
} else {
callback({});
}
}
示例2: listWallets
listWallets() {
return this.db.createReadStream().pipe(
new Transform({
objectMode: true,
write: function(data, enc, next) {
if (data.key.toString().startsWith('wallet')) {
this.push(data.value.toString());
}
next();
}
})
);
}