Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

NFS Guide

fengmk2 edited this page May 7, 2023 · 30 revisions

cnpmjs.org support custom storage, but all the storage need follow the rules:

Protocols

  • async function upload(filepath, options)
    • filepath: upload file path
    • options
      • key: identifie of this file
      • size: file size
  • async function uploadBuffer(fileBuffer, options)
    • fileBuffer: upload file content buffer
    • options
      • key: identifie of this file
      • size: fileBuffer size
      • shasum: fileBuffer sha1
      • shasum256: fileBuffer sha256
  • async function remove(key)
    • key: file identifie
  • async function download(key, savePath, options)[optional]
    • key: file identifie
    • savePath: download path
    • options
      • timeout
  • async function createDownloadStream(key, options)[optional]
    • key: file identifie
    • options
      • timeout
    • return {ReadStream}
  • async function url(key)[optional] url method should be async function too.
    • key: file identifie
  • async function readBytes(key, options)[optional]
    • key: file identifie
    • options
      • timeout
  • async function appendBuffer(fileBuffer, options)[optional]
    • fileBuffer: upload file content buffer
    • options
      • key: identifie of this file

All function are async function.

Support Storage Types

  1. Can download the uploaded file through http request. like qn-cnpm.
  • uploadBuffer: use options.key to customize the filename, then callback {url: 'http://test.com/xxx.tgz'}.
  • url: accept a key and respond download url.
  • remove: remove file by key
  1. Can not download by http request. like sfs-client or oss-cnpm.
  • uploadBuffer: upload the file, and must callback {key: 'xxx'}, so cnpmjs.org can record the key, and use this key to download or remove.
  • download: need provide download api to download the file by key.
  • createDownloadStream: streaming download file by key
  • remove: remove file by key

Present Storage wrappers