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

NFS Guide

fengmk2 edited this page Apr 11, 2015 · 30 revisions

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

Protocols

  • function upload(filepath, options)*
    • filepath: upload file path
    • options
      • key: identifie of this file
      • size: file size
  • function uploadBuffer(fileBuffer, options)*
    • fileBuffer: upload file content buffer
    • options
      • key: identifie of this file
      • size: file size
  • function remove(key)*
    • key: file identifie
  • function download(key, savePath, options)*[optional]
    • key: file identifie
    • savePath: download path
    • options
      • timeout
  • function createStream(key, options)*[optional]
    • key: file identifie
    • options
      • timeout
  • function url(key)[optional]
    • key: file identifie

upload, uploadBuffer, download, createStream, and remove need be yieldables.

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.
  • remove: remove file by key

Present Storage wrappers

  • fs: A filesystem storage wrapper
  • sfs: A wrapper for a simple distribute file storage system sfs
  • qn: qiniu cloud storage service wrapper
  • oss: ali oss storage service wrapper
  • upyun: upyun cloud storage service wrapper

Clone this wiki locally