<commit_before>var MBTiles = require('./mbtiles'),
    Tile = require('./tile'),
    Step = require('step'),
    SphericalMercator = require('./sphericalmercator');

/**
 * Require options keys:
 * - bbox
 * - minzoom
 * - maxzoom
 * - filepath
 * - mapfile
 * - mapfile_dir
 */
function TileBatch(options) {
    this.options = options || {};
    this.mbtiles = new MBTiles(options.filepath);
    var sm = new SphericalMercator({levels: this.options.maxzoom + 1});
    this.xyz = new sm.BBoxXYZ(
        {levels: this.options.maxzoom + 1},
        this.options.bbox,
        this.options.minzoom,
        this.options.maxzoom
    );
}

TileBatch.prototype.setup = function(callback) {
    this.mbtiles.setup(callback);
}

TileBatch.prototype.renderChunk = function(callback) {
    // @TODO make configurable
    // @TODO handle tile compression
    var tiles = this.xyz.next(100);
    var that = this;

    if (!tiles) {
        return callback(null, false);
    }

    Step(
        function() {
            var group = this.group();
            for (var i = 0; i < tiles.length; i++) {
                var tile = new Tile({
                    format: 'png',
                    scheme: 'tile',
                    xyz: [tiles[i][1], tiles[i][2], tiles[i][0]],
                    mapfile: that.options.mapfile,
                    mapfile_dir: that.options.mapfile_dir<commit_msg>Handle metadata insertion for a tile batch.<commit_after>var MBTiles = require('./mbtiles'),
    Tile = require('./tile'),
    Step = require('step'),
    SphericalMercator = require('./sphericalmercator');

/**
 * Require options keys:
 * - bbox
 * - minzoom
 * - maxzoom
 * - filepath
 * - mapfile
 * - mapfile_dir
 * - metadata
 */
function TileBatch(options) {
    this.options = options || {};
    this.mbtiles = new MBTiles(options.filepath);
    var sm = new SphericalMercator({levels: this.options.maxzoom + 1});
    this.xyz = new sm.BBoxXYZ(
        {levels: this.options.maxzoom + 1},
        this.options.bbox,
        this.options.minzoom,
        this.options.maxzoom
    );
}

TileBatch.prototype.setup = function(callback) {
    var that = this;
    Step(
        function() {
            that.mbtiles.setup(this);
        },
        function() {
            that.mbtiles.metadata(that.options.metadata, this);
        },
        function() {
            callback();
        }
    );
}

TileBatch.prototype.renderChunk = function(callback) {
    // @TODO make configurable
    // @TODO handle tile compression
    var tiles = this.xyz.next(100);
    var that = this;

    if (!tiles) {
        return callback(null, false);
    }

    Step(
        function() {
            var group = this.group();
            for (var i = 0; i < tiles.length; i++) {
                var tile = new Tile({
                    format: 'png',
                    scheme: 'tile',
                    xyz: [tiles[i][1], tiles[i][2], tiles[i][0]],
                    mapfile: that.options.mapfile,
                    mapfile_dir: that.options.mapfile_dir
{'fraction_non_alphanumeric': 0.1400329489291598, 'fraction_numerical': 0.005930807248764415, 'mean_word_length': 1.961951219512195, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '5774085', 'n_tokens_mistral': 966, 'n_tokens_neox': 916, 'n_words': 198}