<commit_before>'use strict';
import s3, { bucket } from './';
import { removeObject } from './structure';

export function getPresignedUrl (file) {
  return new Promise((resolve, reject) => {
    s3.presignedPutObject(bucket, file, 24 * 60 * 60, (err, presignedUrl) => {
      if (err) {
        return reject(err);
      }
      return resolve(presignedUrl);
    });
  });
}

export function listenForFile (file) {
  return new Promise((resolve, reject) => {
    var listener = s3.listenBucketNotification(bucket, file, '', ['s3:ObjectCreated:*']);
    listener.on('notification', record => {
      listener.stop();
      return resolve(record);
    });
  });
}

// Proxy of removeObject function, assuming the bucket.
export function removeFile (file) {
  return removeObject(bucket, file);
}

// Get file.
export function getFile (file) {
  return new Promise((resolve, reject) => {
    s3.getObject(bucket, file, (err, dataStream) => {
      if (err) {
        return reject(err);
      }
      return resolve(dataStream);
    });
  });
}

// Copy file.
export function copyFile (oldFile, newFile) {
  return new Promise((resolve, reject) => {
    s3.copyObject(bucket, newFile, `${bucket}/${oldFile}`, null, (err, data) => {
      if (err) {
        return reject(err);
      }
      return resolve();
    });
  });
}

// Get file content.
export function getFileContents (file) {
  return new Promise((resolve, reject) => {
    s3.getObject(bucket, file, (err, dataStream) => {
      if (err) return reject(err);

      var data = '';
      dataStream.on('data', chunk => (data += chunk));
      dataStream.on('end', () => resolve(data));
      dataStream.on('error', () => reject(err));
    });
  });
}

// Get file content in JSON.
export function getJSONFileContents (file) {
  return getFileContents(file)
    .then(result => JSON.parse(result));
}<commit_msg>Add method to post files to s3 via stream<commit_after>'use strict';
import s3, { bucket } from './';
import { removeObject } from './structure';

export function getPresignedUrl (file) {
  return new Promise((resolve, reject) => {
    s3.presignedPutObject(bucket, file, 24 * 60 * 60, (err, presignedUrl) => {
      if (err) {
        return reject(err);
      }
      return resolve(presignedUrl);
    });
  });
}

export function listenForFile (file) {
  return new Promise((resolve, reject) => {
    var listener = s3.listenBucketNotification(bucket, file, '', ['s3:ObjectCreated:*']);
    listener.on('notification', record => {
      listener.stop();
      return resolve(record);
    });
  });
}

// Proxy of removeObject function, assuming the bucket.
export function removeFile (file) {
  return removeObject(bucket, file);
}

// Get file.
export function getFile (file) {
  return new Promise((resolve, reject) => {
    s3.getObject(bucket, file, (err, dataStream) => {
      if (err) {
        return reject(err);
      }
      return resolve(dataStream);
    });
  });
}

// Copy file.
export function copyFile (oldFile, newFile) {
  return new Promise((resolve, reject) => {
    s3.copyObject(bucket, newFile, `${bucket}/${oldFile}`, null, (err, data) => {
      if (err) {
        return reject(err);
      }
      return resolve();
    });
  });
}

// Get file content.
export function getFileContents (file) {
  return new Promise((resolve, reject) => {
    s3.getObject(bucket, file, (err, dataStream) => {
      if (err) return reject(err);

      var data = '';
      dataStream.on('data', chunk => (data += chunk));
      dataStream.on('end', () => resolve(data));
      dataStream.on('error', () => reject(err));
    });
  });
}

// Get file content in JSON.
export function getJSONFileContents (file) {
  return getFileContents(file)
    .then(result => JSON.parse(result));
}

// Put file from stream
export function putFileStream (file, stream) {
  return new Promise((resolve, reject) => {
    s3.putObject(bucket, file, stream, (err, etag) => {
      if (err) return reject(err);
      return resolve(etag);
    });
  });
}
{'fraction_non_alphanumeric': 0.16397113709878078, 'fraction_numerical': 0.006966907190843493, 'mean_word_length': 3.127310061601643, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '2044253', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1228, 'n_words': 328}