本文整理汇总了TypeScript中levelup.LevelUp.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript LevelUp.get方法的具体用法?TypeScript LevelUp.get怎么用?TypeScript LevelUp.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类levelup.LevelUp
的用法示例。
在下文中一共展示了LevelUp.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: loadWallet
async loadWallet(params: { name: string }) {
const { name } = params;
const wallet = (await this.db.get(`wallet|${name}`)) as string;
if (!wallet) {
return;
}
return JSON.parse(wallet);
}
示例2: 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({});
}
}
示例3: isNewFile
public async isNewFile(filepath: string): Promise<boolean> {
try {
await this.files.get(filepath);
return false;
} catch (err) {
switch (err.notFound) {
case true:
return true;
default:
throw err;
}
}
}
示例4: getKey
async getKey(params) {
const { address, name, encryptionKey } = params;
const payload = (await this.db.get(`key|${name}|${address}`)) as string;
const json = JSON.parse(payload) || payload;
const { encKey, pubKey } = json;
if (encryptionKey && pubKey) {
const decrypted = Encryption.decryptPrivateKey(
encKey,
Buffer.from(pubKey, 'hex'),
Buffer.from(encryptionKey, 'hex')
);
return JSON.parse(decrypted);
} else {
return json;
}
}
示例5: handler
public async handler(_: string, payload: any): Promise<void> {
try {
const { filepath, jobType } = payload;
logger.info('Starting work for %s', filepath);
const tag = new Tag(filepath);
const currentValue = await this.files.get(filepath);
const { jobStatus } = currentValue;
logger.debug('Work type: %s', FileJobType[jobType]);
try {
const handled =
jobStatus === FileJobStatus.Pending && existsSync(filepath)
? this.handleFile(filepath, jobType) && true
: false;
currentValue.jobStatus = handled
? FileJobStatus.Complete
: FileJobStatus.Unhandled;
await tag.removeTag('Red');
await tag.removeTag('Yellow');
await tag.addTag('Green');
} catch (err) {
logger.error(err);
currentValue.jobStatus = FileJobStatus.Error;
await tag.removeTag('Green');
await tag.removeTag('Yellow');
await tag.addTag('Red');
} finally {
this.files.put(filepath, currentValue);
}
} catch (err) {
logger.error(err);
}
}