<commit_before>'use strict';

const chalk = require('chalk');
const knox = require('knox');
const mime = require('mime-types');
const promised = require('promised-method');

const WINDOWS_SLASH_REGEX = /\//g;
function replaceWindowsSlash(path) {
	return path.replace(WINDOWS_SLASH_REGEX, '/');
}

module.exports = function s3UploadFactory(knoxOpt, opt) {
	opt = opt || {};
	opt.headers = opt.headers || {};

	const client = knox.createClient(knoxOpt);

	return promised(function s3Uploader(file) {
		if (!file || !file.base || !file.path || !file.contents) {
			throw new TypeError('Expected a vinyl file.');
		}

		const base = replaceWindowsSlash(file.base);
		const path = replaceWindowsSlash(file.path);
		const uploadPath = path.replace(base, opt.uploadPath);

		const headers = JSON.parse(JSON.stringify(opt.headers));

		if (!headers['Content-Type']) {
			const contentType = opt.type || mime.lookup(uploadPath) || 'text/plain';
			const charset = opt.charset || mime.charset(contentType);

			headers['Content-Type'] = contentType;

			if (charset) {
				headers['Content-Type'] += `; charset=${charset}`;
			}
		}

		headers['Content-Length'] = file.contents.length;

		return new Promise((resolve, reject) => {
			client
				.put(uploadPath, headers)
				.on('response', res => {<commit_msg>refact: make charset lowercase (not that it matters)<commit_after>'use strict';

const chalk = require('chalk');
const knox = require('knox');
const mime = require('mime-types');
const promised = require('promised-method');

const WINDOWS_SLASH_REGEX = /\//g;
function replaceWindowsSlash(path) {
	return path.replace(WINDOWS_SLASH_REGEX, '/');
}

module.exports = function s3UploadFactory(knoxOpt, opt) {
	opt = opt || {};
	opt.headers = opt.headers || {};

	const client = knox.createClient(knoxOpt);

	return promised(function s3Uploader(file) {
		if (!file || !file.base || !file.path || !file.contents) {
			throw new TypeError('Expected a vinyl file.');
		}

		const base = replaceWindowsSlash(file.base);
		const path = replaceWindowsSlash(file.path);
		const uploadPath = path.replace(base, opt.uploadPath);

		const headers = JSON.parse(JSON.stringify(opt.headers));

		if (!headers['Content-Type']) {
			const contentType = opt.type || mime.lookup(uploadPath) || 'text/plain';
			const charset = opt.charset || mime.charset(contentType);

			headers['Content-Type'] = contentType;

			if (charset) {
				headers['Content-Type'] += `; charset=${charset.toLowerCase()}`;
			}
		}

		headers['Content-Length'] = file.contents.length;

		return new Promise((resolve, reject) => {
			client
				.put(uploadPath, headers)
				.on('response', res => {
{'fraction_non_alphanumeric': 0.16271186440677965, 'fraction_numerical': 0.0015065913370998117, 'mean_word_length': 4.521829521829522, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5843722', 'n_tokens_mistral': 937, 'n_tokens_neox': 836, 'n_words': 181}