<commit_before>var es = require("event-stream");
var zlib = require("zlib");
var clone = require("clone");

module.exports = function() {
	'use strict';

	function compress(file, callback) {

		 if (file.isNull()) return callback(null, file); // pass along

		// Clone file and append .gz file extension
		var newFile = clone(file);
		newFile.path += '.gz';
		newFile.shortened += '.gz';

		// Check if file is a buffer or a stream
		if(file.isBuffer()) {

			// File contents is a buffer
			zlib.gzip(newFile.contents, function(err, buffer) {
				if (!err) {
					// Set the compressed file contents
					newFile.contents = buffer;
					callback(null, newFile);
				} else {
					callback(err, null);
				}
			});
		} else {

			// File contents is a stream
			var gzipStream = zlib.createGzip();
			var throughStream = es.through();
			newFile.contents = file.contents.pipe(gzipStream).pipe(throughStream);
			callback(null, newFile);
		}
	}

	return es.map(compress);
};
<commit_msg>Removed through stream. Just return gzip stream as file contents.<commit_after>var es = require("event-stream");
var zlib = require("zlib");
var clone = require("clone");

module.exports = function() {
	'use strict';

	function compress(file, callback) {

		 if (file.isNull()) return callback(null, file); // pass along

		// Clone file and append .gz file extension
		var newFile = clone(file);
		newFile.path += '.gz';
		newFile.shortened += '.gz';

		// Check if file is a buffer or a stream
		if(file.isBuffer()) {

			// File contents is a buffer
			zlib.gzip(newFile.contents, function(err, buffer) {
				if (!err) {
					// Set the compressed file contents
					newFile.contents = buffer;
					callback(null, newFile);
				} else {
					callback(err, null);
				}
			});
		} else {

			// File contents is a stream
			var gzipStream = zlib.createGzip();
			newFile.contents = file.contents.pipe(gzipStream);
			callback(null, newFile);
		}
	}

	return es.map(compress);
};

{'fraction_non_alphanumeric': 0.1423487544483986, 'fraction_numerical': 0.0, 'mean_word_length': 3.143157894736842, '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': '3237197', 'n_tokens_mistral': 732, 'n_tokens_neox': 615, 'n_words': 180}