@sumor/storage

存储

一个Sumor Cloud工具。
更多文档

这是一个用于 Node.JS 的轻量级存储库。
它可以连接到各种存储服务,例如阿里云 OSS

CI Test Coverage Audit

安装

npm i @sumor/storage --save

先决条件

Node.JS 版本

需要 Node.JS 版本 18.x 或以上

需要 Node.JS ES 模块

由于该包是用 ES 模块编写的,
请在您的 package.json 文件中修改以下代码:

{
  "type": "module"
}

使用

导入

import { Storage } from '@sumor/storage'

const storage = new Storage(config)

配置格式

阿里云 OSS 示例

{
  "type": "aliyunOSS",
  "accessKeyId": "xxxx",
  "accessKeySecret": "xxx",
  "region": "oss-us-west-1",
  "bucket": "sumor-cloud"
}

存储

存储内容支持文本、缓冲区、流

import { Storage } from '@sumor/storage'

const storage = new Storage(config)

const filename = 'demo.txt'
const content = 'Hello World'

const result = await storage.put(filename, content)

获取

import { Storage } from '@sumor/storage'

const storage = new Storage(config)

const filename = 'demo.txt'

const result = await storage.get(filename)

删除

import { Storage } from '@sumor/storage'

const storage = new Storage(config)

const filename = 'demo.txt'

const result = await storage.delete(filename)