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

kloud

v0.2.1

Published

aliyun OSS(Open Storage Service) lib.

Downloads

19

Readme

kloud

NPM version  Build Status  Dependency Status

aliyun OSS(Open Storage Service) lib. A node wrapper for OSS RESTful API.

Install

npm install kloud --save

Usage

First, create an OSS client:

var client = kloud.createClient({
  accessKeyId: '<your access key id>',
  accessKeySecret: '<your access key secret>',
  host: '<your bucket host>', // region.aliyuncs.com
  bucket: '<your bucket name>'
});

PUT

Use the Client#put(filename, headers) method with a string or buffer to upload some strings to OSS, just like node http.Client request. Return a duplex stream, you can listen for a response event on it, and write the content using req.end(content).

var str = JSON.stringify({ foo: 'bar' });
var req = client.put('test.json', {
  'Content-Type': 'application/json',
  'Content-Length': str.length
});

req.on('response', function(res) {
  if (res.statusCode === 200) {
    console.log('file saved.');
  }
});

req.end(str);

Use the Client#putFile(src, filename, headers, callback) to upload a file to OSS:

client.putFile('./README.md', 'readme.markdown', function(err, res) {
  // res.statusCode === 200
});

Or use the Client#putStream(stream, filename, headers, callback):

http.get('http://google.com/doodle.png', function(res){
  var headers = {
    'Content-Length': res.headers['content-length'],
    'Content-Type': res.headers['content-type']
  };

  client.putStream(res, 'doodle.png', headers, function(err, res){
    // res.statusCode === 200
  });
});

Important: use stream mode you have to set Content-Length header!

fs.stat('./README.md', function(err, stat) {
  var headers = {
    'Content-Length': stat.size,
    'Content-Type': 'text/plain'
  };
  var req = client.put('readme.markdown', headers);

  req.on('response', function(res) {
    // res.statusCode === 200
  });

  fs.createReadStream('./README.md').pipe(req);
})

Also, you can use Client.putBuffer(buffer, filename, headers, callback) to put a string or buffer data:

var buf = new Buffer('hello world');

client.putBuffer(buf, 'test.txt', function(err, res) {});

GET

Use the Client.get(filename, headers) to get an OSS object:

var req = client.get('readme.markdown');
req.on('response', function(res) {
  // res.statusCode === 200

  var chunks = [];
  var chunkLen = 0;

  res.on('data', function(chunk) {
    chunks.push(chunk);
    chunkLen += chunk.length;
  });

  res.on('end', function() {
    console.log(Buffer.concat(chunks, chunkLen).toString());
  });
});

Or use Client#getFile(filename, headers, callback):

client.getFile('readme.markdown', function(err, res) {
  // res.statusCode === 200

  var dest = fs.createWriteSteam('./test.md');
  res.pipe(dest);
});

DELETE

Use Client#del(filename, headers) to delete an OSS object:

client.del('readme.markdown').on('response', function(err, res) {
  // res.statusCode === 200
  // Deleted!
});

Or Client#deleteFile(filename, headers, callback):

client.deleteFile('readme.markdown', function(err, res) {});

You can delete up to 1000 OSS objects at once:

client.deleteMultiple(['test.json', 'readme.markdown'], function(err, res) {});