@ appium/ 强框
Appium 扩展的持续存储
内容提要
此包意在用于 辅料 在 Appium 运行之间需要坚持数据的扩展 。 此类数据的例子可能是设备符号或密钥.
@appium/strongbox 提供简单和可扩展的API,用于管理此类数据,同时抽象出基础存储机制.
说明: 本模块并非用于存储敏感数据.
使用量
首先,创建一个实例: Strongbox数字 :
import {strongbox} from '@appium/strongbox';
const box = strongbox('my-pkg');
这一实例对应独特的数据收集.
在此创建数据的占位符( 您需要提供您想要存储的数据类型 ):
const item = await box.createItem<string>('my unique name');
...或者,如果你已经掌握了数据:
const item: Buffer|string = getSomeData();
const item = await box.createItemWithContents('my unique name', data);
无论哪种方式,都可以读取其内容:
// if the item doesn't exist, this result will be undefined
const contents = await item.read();
或将新数据写入项目:
await item.write('new stuff');
在事先不知道姓名的情况下列出长期存在的物项:
const items = await box.listItems();
listItems 不读取每个文件的内容; 调用 read() 当您需要的时候。 项目顺序遵循文件系统目录行走(不是词典). 它返回一个阵列中的每个项目; 对于可以使用很多内存的大型容器, 更喜欢同位素迭代, 将目录条目流到 opendir 而不是先缓冲所有名称 :
for await (const item of box) {
// ...
}
最后读取的内容 Item 将可在 contents 属性,但该属性的值仅为当前 read()数字 :
const {contents} = item;
API 密码
取而代之的是实际文件,看看这个包船的种类定义.
自定义
-
创建一个执行
Item接口 :import {strongbox, Item} from '@appium/strongbox'; import {Foo, getFoo} from 'somewhere/else'; class FooItem implements Item<Foo> { // ... } -
提供此类作为
defaultCtor选项到strongbox()数字 :const box = strongbox('my-pkg', {defaultCtor: FooItem}); -
像你一样
Strongbox实例:const foo: Foo = getFoo(); const item = await box.createItemWithValue('my unique name', Foo);
默认行为,为好奇者
箱外,一个 Strongbox 实例对应磁盘上的目录,每个 Item (返回人数 createItem()/createItemWithContents())对应该目录中的文件.
该目录 Strongbox 实例由 环境路径 软件包,并具有特定平台.
许可证
版权所有 2023 OpenJS基金会. 许可的 Apache-2.0