<commit_before>'use strict';
var gutil = require('gulp-util');
var through = require('through2');
var uidNumber = require('uid-number');
var defaultMode = 511 & (~process.umask()); // 511 = 0777

module.exports = function (user, group) {
	var firstFile = true;
	var finalUid = typeof user === 'number' ? user : null;
	var finalGid = typeof group === 'number' ? group : null;

	return through.obj(function (file, enc, cb) {
		if (file.isNull()) {
			this.push(file);
			return cb();
		}

		if (file.isStream()) {
			this.emit('error', new gutil.PluginError('gulp-chmod', 'Streaming not supported'));
			return cb();
		}

		file.stat = file.stat || {};
		file.stat.mode = file.stat.mode || defaultMode;

		var finish = function () {
			file.stat.uid = finalUid != null ? finalUid : file.stat.uid;
			file.stat.gid = finalGid != null ? finalGid : file.stat.gid;
			this.push(file);
			cb();
		}.bind(this);

		if (firstFile && typeof user === 'string') {
			uidNumber(user, group, function (err, uid, gid) {
				if (err) {
					this.emit('error', new gutil.PluginError('gulp-chmod', err, {fileName: file.path}));
					return cb();
				}

				finalUid = uid;
				finalGid = gid;

				finish();
			}.bind(this));

			firstFile = false;
			return;
		}<commit_msg>allow streams<commit_after>'use strict';
var gutil = require('gulp-util');
var through = require('through2');
var uidNumber = require('uid-number');
var defaultMode = 511 & (~process.umask()); // 511 = 0777

module.exports = function (user, group) {
	var firstFile = true;
	var finalUid = typeof user === 'number' ? user : null;
	var finalGid = typeof group === 'number' ? group : null;

	return through.obj(function (file, enc, cb) {
		if (file.isNull()) {
			this.push(file);
			return cb();
		}

		file.stat = file.stat || {};
		file.stat.mode = file.stat.mode || defaultMode;

		var finish = function () {
			file.stat.uid = finalUid != null ? finalUid : file.stat.uid;
			file.stat.gid = finalGid != null ? finalGid : file.stat.gid;
			this.push(file);
			cb();
		}.bind(this);

		if (firstFile && typeof user === 'string') {
			uidNumber(user, group, function (err, uid, gid) {
				if (err) {
					this.emit('error', new gutil.PluginError('gulp-chmod', err, {fileName: file.path}));
					return cb();
				}

				finalUid = uid;
				finalGid = gid;

				finish();
			}.bind(this));

			firstFile = false;
			return;
		}
{'fraction_non_alphanumeric': 0.17723645527089457, 'fraction_numerical': 0.009239815203695927, 'mean_word_length': 3.291891891891892, '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': '6968879', 'n_tokens_mistral': 962, 'n_tokens_neox': 817, 'n_words': 209}