当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript levelup.LevelUp类代码示例

本文整理汇总了TypeScript中levelup.LevelUp的典型用法代码示例。如果您正苦于以下问题:TypeScript LevelUp类的具体用法?TypeScript LevelUp怎么用?TypeScript LevelUp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LevelUp类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: buildExistingFilesDb

  public async buildExistingFilesDb(watchPath: string): Promise<number> {
    try {
      const cwd = watchPath;

      const files = await globPromise(`**/*`, {
        cwd
      });

      const filePayload: FilePayload = {
        jobStatus: FileJobStatus.Existing,
        jobType: FileJobType.Unknown
      };

      const existingFiles = files.map(
        (filepath: string): AbstractBatch => ({
          key: path.resolve(cwd, filepath),
          type: 'put',
          value: filePayload
        })
      );

      await this.files.batch(existingFiles);

      return existingFiles.length;
    } catch (error) {
      throw error;
    }
  }
开发者ID:mshick,项目名称:arrivals-osx,代码行数:28,代码来源:dispatcher.ts

示例2: addKeys

 async addKeys(params: {
   name: string;
   keys: Wallet.KeyImport[];
   encryptionKey: string;
 }) {
   const { name, keys, encryptionKey } = params;
   const ops = keys.map(key => {
     let { pubKey } = key;
     pubKey =
       pubKey || new bitcoreLib.PrivateKey(key.privKey).publicKey.toString();
     let payload = {};
     if (pubKey && key.privKey && encryptionKey) {
       const encKey = Encryption.encryptPrivateKey(
         JSON.stringify(key),
         Buffer.from(pubKey, 'hex'),
         Buffer.from(encryptionKey, 'hex')
       );
       payload = { encKey, pubKey };
     }
     return {
       type: 'put',
       key: `key|${name}|${key.address}`,
       value: JSON.stringify(payload)
     };
   });
   if (ops.length > 1) {
     return this.db.batch(ops);
   } else {
     this.db.put(ops[0].key, ops[0].value);
   }
 }
开发者ID:bitpay,项目名称:bitcore,代码行数:31,代码来源:storage.ts

示例3: 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({});
    }
  }
开发者ID:laquereric,项目名称:wexond,代码行数:56,代码来源:storage-area.ts

示例4: enqueueFile

  public async enqueueFile(
    filepath: string,
    filetype: FileJobType
  ): Promise<boolean> {
    try {
      const tag = new Tag(filepath);

      const jobType = filetype;
      const jobStatus = FileJobStatus.Pending;

      const filePayload: FilePayload = {
        jobStatus,
        jobType
      };

      await this.files.put(filepath, filePayload);

      const fileJobPayload: FileJobPayload = {
        filepath,
        jobType
      };

      const jobId = await this.queue.pushPromise(fileJobPayload);

      logger.debug('File enqueued with jobId: %s', jobId);

      await tag.addTag('Yellow');

      return true;
    } catch (err) {
      logger.error('Error in enqueue\n%s', prettyPrint(err));
      return false;
    }
  }
开发者ID:mshick,项目名称:arrivals-osx,代码行数:34,代码来源:dispatcher.ts

示例5: 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);
 }
开发者ID:bitjson,项目名称:bitcore,代码行数:8,代码来源:storage.ts

示例6: callback

 this.get(null, data => {
   const batch = this.db.batch();
   for (const key in data) {
     batch.del(key);
   }
   batch.write(() => {
     callback();
   });
 });
开发者ID:laquereric,项目名称:wexond,代码行数:9,代码来源:storage-area.ts

示例7: remove

  public remove(keys: any, callback: any) {
    if (typeof keys === 'string') {
      this.db.del(keys, err => {
        callback();
      });
    } else if (Array.isArray(keys)) {
      const batch = this.db.batch();

      for (const key of keys) {
        batch.del(key);
      }

      batch.write(() => {
        callback();
      });
    } else {
      // error
    }
  }
开发者ID:laquereric,项目名称:wexond,代码行数:19,代码来源:storage-area.ts

示例8: 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);
    }
  }
开发者ID:mshick,项目名称:arrivals-osx,代码行数:41,代码来源:worker.ts

示例9: 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;
     }
   }
 }
开发者ID:mshick,项目名称:arrivals-osx,代码行数:13,代码来源:dispatcher.ts

示例10: Transform

 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();
       }
     })
   );
 }
开发者ID:bitpay,项目名称:bitcore,代码行数:13,代码来源:storage.ts


注:本文中的levelup.LevelUp类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。