<commit_before>'use strict';

/*

OverZoomer is a storage wrapper. Given a tile source, it will retrieve requested tile from it,
or if missing, will zoom out until it finds a tile, and extract needed portion of it.
 */

var BBPromise = require('bluebird');
var core = require('kartotherian-core');
var zlib = require('zlib');

function OverZoomer(uri, callback) {
    var self = this;
    return BBPromise.try(function () {
        uri = core.normalizeUri(uri);
        if (!uri.query.source) {
            throw Error("Uri must include 'source' query parameter: " + core.formatUri(uri));
        }
        return OverZoomer._tilelive.loadAsync(uri.query.source);
    }).then(function (handler) {
        self.source = handler;
        callback(undefined, self);
    }).catch(function (err) {
        callback(err);
    });
}

OverZoomer.prototype.getTile = function(z, x, y, callback) {
    var self = this;
    getSubTile(z, x, y);

    function getSubTile(bz, bx, by) {
        return self.source.getTile(bz, bx, by, function (err, pbfz, headers) {
            if (bz > 0 && err && err.message === 'Tile does not exist') {
                // Tile is missing, zoom out and repeat
                getSubTile(bz - 1, Math.floor(bx / 2), Math.floor(by / 2));
            } else if (err || bz === z || !pbfz || pbfz.length === 0) {
                // either this is exactly what we were asked for initially, or an error
                callback(err, pbfz, headers);
            } else {
                // Extract portion of the higher zoom tile as a new tile
                headers.OverzoomFrom = bz;
                core.uncompressAsync(pbfz)
                    .then(function (pbf) {
                        return core.extractSubTileAsync(pbf, z, x, y, bz, bx, by);
                    }).then(function (pbf) {
                        return core.compressPbfAsync2(pbf, headers);
                    }).nodeify(callback, {spread: true});
            }
        });
    }
};
<commit_msg>Minor fixe to match core<commit_after>'use strict';

/*

OverZoomer is a storage wrapper. Given a tile source, it will retrieve requested tile from it,
or if missing, will zoom out until it finds a tile, and extract needed portion of it.
 */

var BBPromise = require('bluebird');
var core = require('kartotherian-core');
var zlib = require('zlib');

function OverZoomer(uri, callback) {
    var self = this;
    return BBPromise.try(function () {
        uri = core.normalizeUri(uri);
        if (!uri.query.source) {
            throw Error("Uri must include 'source' query parameter: " + JSON.stringify(uri));
        }
        return OverZoomer._tilelive.loadAsync(uri.query.source);
    }).then(function (handler) {
        self.source = handler;
        callback(undefined, self);
    }).catch(function (err) {
        callback(err);
    });
}

OverZoomer.prototype.getTile = function(z, x, y, callback) {
    var self = this;
    getSubTile(z, x, y);

    function getSubTile(bz, bx, by) {
        return self.source.getTile(bz, bx, by, function (err, pbfz, headers) {
            if (bz > 0 && err && core.isNoTileError(err)) {
                // Tile is missing, zoom out and repeat
                getSubTile(bz - 1, Math.floor(bx / 2), Math.floor(by / 2));
            } else if (err || bz === z || !pbfz || pbfz.length === 0) {
                // either this is exactly what we were asked for initially, or an error
                callback(err, pbfz, headers);
            } else {
                // Extract portion of the higher zoom tile as a new tile
                headers.OverzoomFrom = bz;
                core.uncompressAsync(pbfz)
                    .then(function (pbf) {
                        return core.extractSubTileAsync(pbf, z, x, y, bz, bx, by);
                    }).then(function (pbf) {
                        return core.compressPbfAsync2(pbf, headers);
                    }).nodeify(callback, {spread: true});
            }
        });
    }
};

{'fraction_non_alphanumeric': 0.12402515723270441, 'fraction_numerical': 0.0030188679245283017, 'mean_word_length': 1.9939759036144578, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2506410', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1152, 'n_words': 354}