<commit_before>(function() {
    'use strict';
    
    var DIR         = '../',
        DIR_SERVER  = DIR + 'server/',
        files       = require(DIR_SERVER + 'files'),
        ponse       = require(DIR_SERVER + 'ponse'),
        
        Minify      = require(DIR_SERVER + 'minify'),
        
        Util        = require(DIR + 'util'),
        
        path        = require('path'),
        zlib        = require('zlib'),
        
        FILE        = __dirname + '/../join.js',
        
        PREFIX      = '/join';
    
    module.exports  = function(options) {
        return join.bind(null, options);
    };
    
    function join(options, req, res, next) {
        var prefix, dir,
            names,
            isMinify,
            isFunc,
            exec        = Util.exec,
            read        = exec.with(readPipe, req, res),
            path        = ponse.getPathName(req),
            regExp      = new RegExp('^' + PREFIX + ':'),
            regExpFile  = new RegExp('^' + PREFIX + '/join.js$'),
            isJoin      = path.match(regExp),
            isJoinFile  = path.match(regExpFile);
        
        if (!options)
            options = {};
        
        isFunc  = Util.isFunction(options.minify);
        
        if (isFunc)
            isMinify = options.minify();
        else
            isMinify = options.minify;
        
        if (!isJoin) {
            next();
        } else {
            prefix  = options.prefix || PREFIX;
            dir     = options.dir || __dirname + '/../../';
            
            if (isJoinFile)
                names = [FILE];
            else
                names = parse(prefix, dir, path);
            
            exec.if(!isMinify, function(namesNew) {
                var is      = Util.isArray(namesNew);
                
                if (is)
                    names = namesNew;
                
                read(names);
            }, function(callback) {
                uglify(names, callback);
            });
        }
        
        return isJoin;
    }
    
    function parse(prefix, dir, url) {
        var names,
            isStr    = typeof url === 'string';
        
        if (!isStr)
            throw(Error('url must be string!'));
            
        names = url.replace(prefix + ':', '')
                   .split(':')
                   .map(function(name) {
                        return path.join(dir, name);
                   });
        
        return names;
    }
    
    function readPipe(req, res, names) {
        var stream,
            path        = ponse.getPathName(req),
            gzip        = zlib.createGzip(),
            isGzip      = ponse.isGZIP(req);
            
        ponse.setHeader({
            name        : names[0],
            cache       : true,
            gzip        : isGzip,
            request     : req,
            response    : res
        });
        
        stream = isGzip ? gzip : res;
        
        files.readPipe(names, stream, function(error) {
            var msg = '';
            
            if (error) {
                Util.log(error);
                msg = error.message;
                
                if (res.headersSent)
                    stream.end(msg);
                else
                    ponse.sendError(msg, {
                        name        : path,
                        gzip        : isGzip,
                        request     : req,
                        response    : res
                    });
            }
        }
        );
        
        /* 
         * pipe should be setted up after
         * readPipe called with stream param
         */
        if (isGzip)
            gzip.pipe(res);
    }
    
    function minify(name, callback) {<commit_msg>chore(join) rm "\n"<commit_after>(function() {
    'use strict';
    
    var DIR         = '../',
        DIR_SERVER  = DIR + 'server/',
        files       = require(DIR_SERVER + 'files'),
        ponse       = require(DIR_SERVER + 'ponse'),
        
        Minify      = require(DIR_SERVER + 'minify'),
        
        Util        = require(DIR + 'util'),
        
        path        = require('path'),
        zlib        = require('zlib'),
        
        FILE        = __dirname + '/../join.js',
        
        PREFIX      = '/join';
    
    module.exports  = function(options) {
        return join.bind(null, options);
    };
    
    function join(options, req, res, next) {
        var prefix, dir,
            names,
            isMinify,
            isFunc,
            exec        = Util.exec,
            read        = exec.with(readPipe, req, res),
            path        = ponse.getPathName(req),
            regExp      = new RegExp('^' + PREFIX + ':'),
            regExpFile  = new RegExp('^' + PREFIX + '/join.js$'),
            isJoin      = path.match(regExp),
            isJoinFile  = path.match(regExpFile);
        
        if (!options)
            options = {};
        
        isFunc  = Util.isFunction(options.minify);
        
        if (isFunc)
            isMinify = options.minify();
        else
            isMinify = options.minify;
        
        if (!isJoin) {
            next();
        } else {
            prefix  = options.prefix || PREFIX;
            dir     = options.dir || __dirname + '/../../';
            
            if (isJoinFile)
                names = [FILE];
            else
                names = parse(prefix, dir, path);
            
            exec.if(!isMinify, function(namesNew) {
                var is      = Util.isArray(namesNew);
                
                if (is)
                    names = namesNew;
                
                read(names);
            }, function(callback) {
                uglify(names, callback);
            });
        }
        
        return isJoin;
    }
    
    function parse(prefix, dir, url) {
        var names,
            isStr    = typeof url === 'string';
        
        if (!isStr)
            throw(Error('url must be string!'));
            
        names = url.replace(prefix + ':', '')
                   .split(':')
                   .map(function(name) {
                        return path.join(dir, name);
                   });
        
        return names;
    }
    
    function readPipe(req, res, names) {
        var stream,
            path        = ponse.getPathName(req),
            gzip        = zlib.createGzip(),
            isGzip      = ponse.isGZIP(req);
            
        ponse.setHeader({
            name        : names[0],
            cache       : true,
            gzip        : isGzip,
            request     : req,
            response    : res
        });
        
        stream = isGzip ? gzip : res;
        
        files.readPipe(names, stream, function(error) {
            var msg = '';
            
            if (error) {
                Util.log(error);
                msg = error.message;
                
                if (res.headersSent)
                    stream.end(msg);
                else
                    ponse.sendError(msg, {
                        name        : path,
                        gzip        : isGzip,
                        request     : req,
                        response    : res
                    });
            }
        });
        
        /* 
         * pipe should be setted up after
         * readPipe called with stream param
         */
        if (isGzip)
            gzip.pipe(res);
    }
    
    function minify(name, callback) {
{'fraction_non_alphanumeric': 0.10943496096334525, 'fraction_numerical': 0.00026465528648934763, 'mean_word_length': 0.9158428390367553, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1633039', 'n_tokens_mistral': 2036, 'n_tokens_neox': 1969, 'n_words': 410}