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 🙏

© 2026 – Pkg Stats / Ryan Hefner

mss-sdk

v2.0.0

Published

MSS SDK for JavaScript

Readme

mss-sdk-js

美团云存储(MSS) SDK for Node.js

Installation

npm install mss-sdk

Usage

初始化MSS

var MSS = require('mss-sdk');

配置

方法1:

// 参考sample/config1.js

var config = new MSS.Config({
	accessKeyId: '你的accessKey', 
	secretAccessKey: '你的secretKey'
});

//全局生效:
MSS.config = config;
方法2:

创建一个json文件config.json:


{
	"accessKeyId": "你的accessKey", 
	"secretAccessKey": "你的secretKey"
}

加载config.json:


// 参考sample/config2.js

//全局生效:
MSS.config.loadFromPath('./config.json');
方法3:

// 参考sample/config3.js

var config = new MSS.Config({
	accessKeyId: '你的accessKey', 
	secretAccessKey: '你的secretKey'
});

//实例化:
var s3 = new MSS.S3();
//当前实例生效:
s3.config = config;
方法4:

// 参考sample/config4.js

//实例化,当前实例生效:
var s3 = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey'
});

实例化

示例1:

var s3 = new MSS.S3();
示例2:

var mybucket = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey'
});
示例3:

// 参考sample/inst3.js

var mybucket = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey',
  params:{
    Bucket: 'mybucket'
  }
});
示例4:

// 参考sample/inst4.js

var mykey = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey',
  params:{
    Bucket: 'mybucket',
    Key: 'myObject'
  }
});

调用

创建一个bucket并上传一个文件:

// 参考sample/create_bucket.js

var s3 = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey',
  params:{
    Bucket: 'myBucket'
  }
});

s3.createBucket(function() {
  var data = {Key: 'Hello', Body: 'Word!'};
  s3.putObject(data, function(err, data) {
    if (err) {
      console.log("Error uploading data: ", err);
    } else {
      console.log("Successfully uploaded data to %s/Hello", 'myBucket');
    }
  });
});
列出所有bucket:

// 参考sample/list_buckets.js

var s3 = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey'
});

s3.listBuckets(function(err, data) {
	if (err)
		console.log(err, err.stack);
	else
		console.log(data);
});
列出bucket中的文件:

// 参考sample/list_objects.js

var s3 = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey'
});

var params = {
  Bucket: 'myBucket',     //required
  Delimiter: '/',         //用'/'折叠伪子目录
  Marker: '',             //分页标签
  MaxKeys: 100,           //最大成员数
  Prefix: ''              //按前缀查询
};

s3.listObjects(params, function(err, data) {
  if (err)
    console.log(err, err.stack);
  else
    console.log(data);
});
下载文件示例1:

// 参考sample/download1.js

var s3 = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey'
});

var params = {
  Bucket: 'myBucket',
  Key: 'myObject'};
var file = require('fs').createWriteStream('./download/file1');
s3.getObject(params).createReadStream().pipe(file);
下载文件示例2:

// 参考sample/download2.js

var s3 = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey'
});

var params = {
  Bucket: 'myBucket',
  Key: 'myObject'};
var file = require('fs').createWriteStream('./download/file2');

s3.getObject(params).on('httpData', function(chunk) {
	file.write(chunk); 
}).on('httpDone', function() {
	file.end();
}).on('httpDownloadProgress', function(progress) {
	console.log(progress);
}).on('error', function(error) {
	console.log(error);
}).on('success', function() {
	console.log('success');
}).on('httpHeaders', function(statusCode, headers) {
	console.log('statusCode: ' + statusCode + "\n", headers);
}).send();
上传文件示例1:

// 参考sample/upload1.js

var s3 = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey'
});

var file = require('fs').createReadStream('./upload/file');

var params = {
  Bucket: 'myBucket',
  Key: 'upload/file1',
  Body: file
};

s3.putObject(params).on('httpHeaders', function(statusCode, headers) {
  console.log(headers);
}).on('httpUploadProgress', function(progress) {
  console.log(progress);
}).on('error', function(error) {
  console.log(error);
}).on('success', function() {
  console.log('success');
}).send();
上传文件示例2:

// 参考sample/upload2.js

var s3 = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey'
});

var fileBuffer = require('fs').readFileSync('./upload/file');

s3.putObject({
  Bucket: 'myBucket',
  Key: 'upload/file2',
  Body: fileBuffer
}, function(error, response) {
  if (error) {
    console.log(error);
  } else {
    console.log('success');
  }
});
上传文件示例3:

// 参考sample/upload3.js

var s3 = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey',
  params:{
    Bucket: 'myBucket'
  }
});

var data = {Key: 'Hello', Body: 'World!'};
s3.putObject(data, function(err, data) {
  if (err) {
    console.log("Error uploading data: ", err);
  } else {
    console.log("Successfully uploaded data to %s/Hello", 'myBucket');
  }
});
获取bucket的acl信息:

// 参考sample/get_acl.js

var s3 = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey',
  params:{
    Bucket: 'myBucket'
  }
});

s3bucket.getBucketAcl(function(err, data) {
	if (err) {
		console.log(err);	// an error occurred
	} else {
		console.log(data);	// successful response
	}
});
设置bucket的acl信息:

// 参考sample/put_acl.js

var s3 = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey'
});

var params = {
  Bucket: 'myBucket',
  ACL: 'private'
};

s3.putBucketAcl(params, function(err, data) {
  if (err) {
    console.log(err);
  } else {
    console.log("set private success");
    params["ACL"] = 'public-read'
    s3.putBucketAcl(params, function(err, data) {
      if (err) {
        console.log(err);
      } else {
        console.log("set public-read success");
      }
    });
  }
});
删除一个文件:

// 参考sample/delete_object.js

var s3 = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey'
});

var params = {
  Bucket: 'myBucket',
  Key: 'myObject'
};

s3.deleteObject(params, function(err, data) {
	if (err) {
		console.log(err);
	} else {
		console.log("success");
	}
});
删除一个bucket:

// 参考sample/delete_bucket.js

var s3 = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey'
});

var params = {Bucket: 'myBucket'};

s3.deleteBucket(params, function(err, data) {
	if (err) {
		console.log(err);
	} else {
		console.log("success");
	}
});
获取一个带有签名的用于下载的url:

// 参考sample/get_presign_url.js

var s3 = new MSS.S3({
  accessKeyId: '你的accessKey',
  secretAccessKey: '你的secretKey'
});

// This URL will expire in one minute (60 seconds)
var params = {
  Bucket: 'myBucket',
  Key: 'myObject',
  Expires: 60
};

var url = s3.getSignedUrl('getObject', params);
console.log("The URL to GET is [%s]", url);

var url = s3.getSignedUrl('headObject', params);
console.log("The URL to HEAD is [%s]", url);
分片上传:

// 代码较长请参考sample/multipart_upload.js