npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

coa-ali-oss

v1.1.0

Published

轻量的阿里云OSS库 for Node.js

Downloads

16

Readme

coa-ali-oss

GitHub license npm version npm downloads PRs Welcome

轻量的阿里云 OSS 库 for Node.js

来源于一个实际生产项目,将常用的 API 和业务解耦后封装成此库,尚未覆盖到阿里云 OSS 的全部操作。后续会根据实际使用情况优化和扩充新的服务。若需用到其他完整接口,可以直接使用阿里云官方 SDK ali-oss

特征

  • 轻量 相对于官方的 SDK,无第三方依赖,更轻量
  • COA 友好 配合 COA 使用,效率更高,报错信息更友好
  • TypeScript 使用 TypeScript 编写,类型约束,IDE 友好

用法

安装

yarn add coa-ali-oss

创建配置实例

import { CoaAliOssBin } from 'coa-ali-oss'

// bucket配置
const ossBucketConfig = {
  accessKeyId: 'LTAIOKxxxxxxWSue9q',
  accessKeySecret: 'pyTLRH0sGooAxxxxxxxxxxxxxxxxxANqPedamD',
  region: 'oss-cn-shanghai',
  bucket: 'bucket-name',
  origin: 'https://example.coajs.com/',
}

// 创建一个配置实例
const ossBucketBin = new CoaAliOssBin(ossBucketConfig)

操作 Object

操作 Object 的原始 API 详见 阿里云帮助文档

import { CoaAliOssObjectService } from 'coa-ali-oss'

// 创建一个Object服务
const objectService = new CoaAliOssObjectService(ossBucketBin)

// 获取前端上传图片所需的token,图片路径前缀必传
// 前端上传图片机制详见 https://help.aliyun.com/document_detail/31926.html
await objectService.token('user/avatar')

// 从服务器获取数据
await objectService.get('user/avatar/001.png')

// 从服务器获取元信息数据
await objectService.head('user/avatar/001.png')

// 将服务器文件下载到本地
await objectService.download(
  'user/avatar/001.png',
  '/local-path/avatar/001.png'
)

// 将Buffer写入服务器
await objectService.put(
  'user/avatar/002.png',
  Buffer.from([
    /*buffer数据*/
  ])
)

// 将本地文件上传到服务器
await objectService.download(
  'user/avatar/002.png',
  '/local-path/avatar/002.png'
)

// 将服务器上文件复制到另一个地方
await objectService.copy('user/avatar/001.png', 'new/avatar/001.png')

// 删除服务器上的文件
await objectService.delete('user/avatar/002.png')

// 获取图片的基本信息
await objectService.imageInfo('user/avatar/001.png') // { width:1280, height:720, fileSize:160000 }