<commit_before>var aws = require('aws-sdk')
  , util = require('util')
  , url = require('url')
  , qs = require('querystring')
  , s3
  ;

if (process.env.AWS_CREDENTIALS_FILE) {
  aws.config.loadFromPath(process.env.AWS_CREDENTIALS_FILE);
} else {
  aws.config.loadFromPath('./aws-credentials.json');
}

aws.config.update({region:'us-east-1'});
s3 = new aws.S3();

exports = module.exports = S3Tiles;

function S3Tiles(uri, callback) {
  if (typeof uri === 'string') {
    uri = url.parse(uri, true);
  } else if (typeof uri.query === 'string') {
    uri.query = qs.parse(uri.query);
  }
  
  this._isWriting = 0;
  this.contentType = 'image/jpeg';
  
  var parts = uri.path.split('/');
  if (parts.length !== 2) {
    throw new Error('Invalid uri, must be formatted as s3tiles://<bucket>/<tileset>#<content-type>');
  }
  if (uri.hash) {
    this.contentType = uri.hash.split('#')[1];
  } else {
    console.log('warning: no content-type specified, defaulting to %s.', this.contentType);
  }
  
  var bucket = this.bucket = parts[0];
  this.tileset = parts[1];
  
  var that = this;
  s3.headBucket({"Bucket":bucket}, function(err, data) {
    if (err) {
      console.log('Bucket ' + bucket + ' missing, creating bucket (%s)', util.inspect(err));
      s3.createBucket({"Bucket":bucket})
        .on('success', function(response) { 
          console.log('bucket created.');
          callback(null, that);
        })
        .on('error', function(response) {
          callback(new Error(util.format('error creating bucket %s', JSON.stringify(response))));<commit_msg>Use uri.host for the bucket name and uri.path for the tileset name<commit_after>var aws = require('aws-sdk')
  , util = require('util')
  , url = require('url')
  , qs = require('querystring')
  , s3
  ;

if (process.env.AWS_CREDENTIALS_FILE) {
  aws.config.loadFromPath(process.env.AWS_CREDENTIALS_FILE);
} else {
  aws.config.loadFromPath('./aws-credentials.json');
}

aws.config.update({region:'us-east-1'});
s3 = new aws.S3();

exports = module.exports = S3Tiles;

function S3Tiles(uri, callback) {
  if (typeof uri === 'string') {
    uri = url.parse(uri, true);
  } else if (typeof uri.query === 'string') {
    uri.query = qs.parse(uri.query);
  }
  
  this._isWriting = 0;
  this.contentType = 'image/jpeg';

  if (uri.hash) {
    this.contentType = uri.hash.split('#')[1];
  } else {
    console.log('warning: no content-type specified, defaulting to %s.', this.contentType);
  }
  
  var bucket = this.bucket = uri.host;
  this.tileset = uri.path.split('/')[1];
  
  var that = this;
  s3.headBucket({"Bucket":bucket}, function(err, data) {
    if (err) {
      console.log('Bucket ' + bucket + ' missing, creating bucket (%s)', util.inspect(err));
      s3.createBucket({"Bucket":bucket})
        .on('success', function(response) { 
          console.log('bucket created.');
          callback(null, that);
        })
        .on('error', function(response) {
          callback(new Error(util.format('error creating bucket %s', JSON.stringify(response))));
{'fraction_non_alphanumeric': 0.17915844838921763, 'fraction_numerical': 0.00821827744904668, 'mean_word_length': 3.340941512125535, 'pattern_counts': {'":': 4, '<': 6, '<?xml version=': 0, '>': 6, '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': '851879', 'n_tokens_mistral': 1059, 'n_tokens_neox': 1051, 'n_words': 209}