andrewrk / node-s3-client

high level amazon s3 client for node.js
MIT License
1k stars 305 forks source link

Improve uploadDir `getS3Params` callback documentation #172

Open ChrisBAshton opened 7 years ago

ChrisBAshton commented 7 years ago

The example code in the README is a little unclear at the moment:

function getS3Params(localFile, stat, callback) {
  // call callback like this:
  var err = new Error(...); // only if there is an error
  var s3Params = { // if there is no error
    ContentType: getMimeType(localFile), // just an example
  };
  // pass `null` for `s3Params` if you want to skip uploading this file.
  callback(err, s3Params);
}

Questions:

Please consider changing to something like:

function getS3Params(localFile, stat, callback) {
  if (thereIsAProblem()) {
    callback(new Error("Some error message..."));
  }
  else if(weDoNotWantToUpload(localFile))) {
    callback(undefined, null);
  }
  else {
    var s3Params = {
      ContentType: getMimeType(localFile), // just an example
    };
    callback(undefined, s3Params);
  }
}