@cx12/kvfile
v0.1.0
Published
Store files in KV backends with optional chunking.
Readme
kvfile
使用各种KV存储存储文件的JS库
共用逻辑
初始化
kvf = new KVFile({ cloud: "aliyun", kv, chunk: true, csize: 1024, bin: false }) cloud为提供商,kv为底层KV实例,chunk为是否启用分块,csize为分块大小(单位MB),bin为是否启用二进制,禁用时使用base64
分块
将文件分成多块,每块大小为csize,增加{文件名}_meta存储分块信息和大小
读取
kvf.read("文件名")
写入
kvf.write("文件名", 数据)
删除
kvf.delete("文件名")
阿里云
API
获取实例
const edgeKv = new EdgeKV({ namespace: "ns"});
获取值
get(key[, {type: “type”}])
写入/更新值
put(key,value)
删除KV对
delete(key)
示例
const { KVFile } = require("./index");
const edgeKv = new EdgeKV({ namespace: "ns" });
const kvf = new KVFile({
cloud: "aliyun",
kv: edgeKv,
chunk: true,
csize: 10,
bin: false,
});
await kvf.write("hello.txt", "hello world");
const content = await kvf.read("hello.txt");
await kvf.delete("hello.txt");