<commit_before>/*
 * files.js: Instance methods for working with files from AWS S3
 *
 * (C) 2012 <NAME>, <NAME>, <NAME> & the Contributors.
 *
 */

var base = require('../../../core/storage'),
    pkgcloud = require('../../../../../lib/pkgcloud'),
    through = require('through2'),
    storage = pkgcloud.providers.amazon.storage,
    _ = require('underscore');

//
// ### function removeFile (container, file, callback)
// #### @container {string} Name of the container to destroy the file in
// #### @file {string} Name of the file to destroy.
// #### @callback {function} Continuation to respond to when complete.
// Destroys the `file` in the specified `container`.
//
exports.removeFile = function (container, file, callback) {
  var self = this;

  if (container instanceof storage.Container) {
    container = container.name;
  }

  if (file instanceof storage.File) {
    file = file.name;
  }

  self.s3.deleteObject({
    Bucket: container,
    Key: file
  }, function(err, data) {
    return err
      ? callback(err)
      : callback(null, !!data.DeleteMarker);
  });
};

exports.upload = function (options) {
  var self = this;

  // check for deprecated calling with a callback
  if (typeof arguments[arguments.length - 1] === 'function') {
    self.emit('log::warn', 'storage.upload no longer supports calling with a callback');
  }

  var s3Options = {
    Bucket: options.container instanceof base.Container ? options.container.name : options.container,
    Key: options.remote instanceof base.File ? options.remote.name : options.remote
  };

  if (options.contentType) {
    s3Options.ContentType = options.contentType;
  }

  // use ACL until a more obvious permission generalization is available
  if (options.acl) {
    s3Options.ACL = options.acl;
  }

  var proxyStream = through(),<commit_msg>adding AWS specific options for cache control and file encryption<commit_after>/*
 * files.js: Instance methods for working with files from AWS S3
 *
 * (C) 2012 <NAME>, <NAME>, <NAME> & the Contributors.
 *
 */

var base = require('../../../core/storage'),
    pkgcloud = require('../../../../../lib/pkgcloud'),
    through = require('through2'),
    storage = pkgcloud.providers.amazon.storage,
    _ = require('underscore');

//
// ### function removeFile (container, file, callback)
// #### @container {string} Name of the container to destroy the file in
// #### @file {string} Name of the file to destroy.
// #### @callback {function} Continuation to respond to when complete.
// Destroys the `file` in the specified `container`.
//
exports.removeFile = function (container, file, callback) {
  var self = this;

  if (container instanceof storage.Container) {
    container = container.name;
  }

  if (file instanceof storage.File) {
    file = file.name;
  }

  self.s3.deleteObject({
    Bucket: container,
    Key: file
  }, function(err, data) {
    return err
      ? callback(err)
      : callback(null, !!data.DeleteMarker);
  });
};

exports.upload = function (options) {
  var self = this;

  // check for deprecated calling with a callback
  if (typeof arguments[arguments.length - 1] === 'function') {
    self.emit('log::warn', 'storage.upload no longer supports calling with a callback');
  }

  var s3Options = {
    Bucket: options.container instanceof base.Container ? options.container.name : options.container,
    Key: options.remote instanceof base.File ? options.remote.name : options.remote
  };

  if (options.contentType) {
    s3Options.ContentType = options.contentType;
  }

  // use ACL until a more obvious permission generalization is available
  if (options.acl) {
    s3Options.ACL = options.acl;
  }

  // add AWS specific options
  if (options.cacheControl) {
    s3Options.CacheControl = options.cacheControl;
  }

  if (options.ServerSideEncryption) {
    s3Options.ServerSideEncryption = options.ServerSideEncryption;
  }

  var proxyStream = through(),
{'fraction_non_alphanumeric': 0.1388463501786626, 'fraction_numerical': 0.006125574272588055, 'mean_word_length': 3.2924424972617743, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6334643', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1118, 'n_words': 342}