<commit_before>'use strict';
var chalk = require('chalk');
var defaults = require('lodash/defaults');
var log = require('fancy-log');
var path = require('path');
var PluginError = require('plugin-error');
var through = require('through2');
var Vinyl = require('vinyl');

var pluginName = 'gulp-sitemap';
var sitemap = require('./lib/sitemap');

module.exports = function (options) {
    var config = defaults(options || {}, {
        changefreq: undefined,
        fileName: 'sitemap.xml',
        lastmod: null,
        mappings: [],
        newLine: '\n',
        priority: undefined,
        spacing: '    ',
        verbose: false
    });
    var entries = [];
    var firstFile;
    var msg;

    if (!config.siteUrl) {
        msg = 'siteUrl is a required param';
        throw new PluginError(pluginName, msg);
    }
    if (options.changeFreq) {
        msg = chalk.magenta('changeFreq') + ' has been deprecated. Please use ' + chalk.cyan('changefreq');
        throw new PluginError(pluginName, msg);
    }
    // site url should have a trailing slash
    if (config.siteUrl.slice(-1) !== '/') {
        config.siteUrl = config.siteUrl + '/';
    }

    return through.obj(function (file, enc, callback) {
            //we handle null files (that have no contents), but not dirs
            if (file.isDirectory()) {
                return callback(null, file);
            }

            if (file.isStream()) {
                msg = 'Streaming not supported';
                return callback(new PluginError(pluginName), msg);
            }

            //skip 404 file
            if (/404\.html?$/i.test(file.relative)) {
                return callback();
            }

            if (!firstFile) {
                firstFile = file;
            }

            var entry = sitemap.getEntryConfig(file, config);
            entries.push(entry);
            callback();
        },
        function (callback) {
            if (!firstFile) {
                return callback();
            }
            var contents = sitemap.prepareSitemap(entries, config);
            if (options.verbose) {
                msg = 'Files in sitemap: ' + entries.length;
                log(pluginName, msg);
            }
            //create and push new vinyl file for sitemap
            this.push(new Vinyl({
                cwd: firstFile.cwd,
                base: firstFile.cwd,
                path: path.join(firstFile.cwd, config.fileName),
                contents: new Buffer(contents)
            }));
            callback();
        });
};<commit_msg>change `new Buffer` to `Buffer.from`<commit_after>'use strict';
var chalk = require('chalk');
var defaults = require('lodash/defaults');
var log = require('fancy-log');
var path = require('path');
var PluginError = require('plugin-error');
var through = require('through2');
var Vinyl = require('vinyl');

var pluginName = 'gulp-sitemap';
var sitemap = require('./lib/sitemap');

module.exports = function (options) {
    var config = defaults(options || {}, {
        changefreq: undefined,
        fileName: 'sitemap.xml',
        lastmod: null,
        mappings: [],
        newLine: '\n',
        priority: undefined,
        spacing: '    ',
        verbose: false
    });
    var entries = [];
    var firstFile;
    var msg;

    if (!config.siteUrl) {
        msg = 'siteUrl is a required param';
        throw new PluginError(pluginName, msg);
    }
    if (options.changeFreq) {
        msg = chalk.magenta('changeFreq') + ' has been deprecated. Please use ' + chalk.cyan('changefreq');
        throw new PluginError(pluginName, msg);
    }
    // site url should have a trailing slash
    if (config.siteUrl.slice(-1) !== '/') {
        config.siteUrl = config.siteUrl + '/';
    }

    return through.obj(function (file, enc, callback) {
            //we handle null files (that have no contents), but not dirs
            if (file.isDirectory()) {
                return callback(null, file);
            }

            if (file.isStream()) {
                msg = 'Streaming not supported';
                return callback(new PluginError(pluginName), msg);
            }

            //skip 404 file
            if (/404\.html?$/i.test(file.relative)) {
                return callback();
            }

            if (!firstFile) {
                firstFile = file;
            }

            var entry = sitemap.getEntryConfig(file, config);
            entries.push(entry);
            callback();
        },
        function (callback) {
            if (!firstFile) {
                return callback();
            }
            var contents = sitemap.prepareSitemap(entries, config);
            if (options.verbose) {
                msg = 'Files in sitemap: ' + entries.length;
                log(pluginName, msg);
            }
            //create and push new vinyl file for sitemap
            this.push(new Vinyl({
                cwd: firstFile.cwd,
                base: firstFile.cwd,
                path: path.join(firstFile.cwd, config.fileName),
                contents: Buffer.from(contents)
            }));
            callback();
        });
};
{'fraction_non_alphanumeric': 0.12786630392537893, 'fraction_numerical': 0.003109211037699184, 'mean_word_length': 1.7290562036055144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3411798', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1379, 'n_words': 363}