<commit_before>/**
 * @file Modify the file system
 * @author Scimonster
 * @license {@link LICENSE} (AGPL)
 * @module mod
 * @requre fs-extra
 */

var fs = require('fs-extra');

/**
 * POST requests to /mod
 * @param {Object} req Express request object
 * @param {Object} res Express response object
 */
exports.master = function(req, res) {
	req.body.file = decodeURIComponent(req.body.file); // set up
	exports[req.body.action](req, res); // and do it
};

/**
 * Create a directory
 * @param {Object} req Express request object
 * @param {Object} res Express response object
 */
exports.mkdir = function(req, res) {
	fs.mkdirs(req.body.file, function(e) { // make parent dirs too, just in case
		res.send(!!e);
	});
};

/**
 * Create a file
 * @param {Object} req Express request object
 * @param {Object} res Express response object
 */
exports.mkfile = function(req, res) {
	fs.open(req.body.file, 'wx', function(e, fd) { // open the file for writing if it doesn't exist
		if (fd && req.body.content) { // write the content to it
			fs.write(fd, new Buffer(req.body.content), 0, req.body.content, null, function(err, written) {
				res.send(written);
			});
		} else {
			res.send(!!e); // send success
		}
	});<commit_msg>mod.js: Fixed issue with mkfile<commit_after>/**
 * @file Modify the file system
 * @author Scimonster
 * @license {@link LICENSE} (AGPL)
 * @module mod
 * @requre fs-extra
 */

var fs = require('fs-extra');

/**
 * POST requests to /mod
 * @param {Object} req Express request object
 * @param {Object} res Express response object
 */
exports.master = function(req, res) {
	req.body.file = decodeURIComponent(req.body.file); // set up
	exports[req.body.action](req, res); // and do it
};

/**
 * Create a directory
 * @param {Object} req Express request object
 * @param {Object} res Express response object
 */
exports.mkdir = function(req, res) {
	fs.mkdirs(req.body.file, function(e) { // make parent dirs too, just in case
		res.send(!!e);
	});
};

/**
 * Create a file
 * @param {Object} req Express request object
 * @param {Object} res Express response object
 */
exports.mkfile = function(req, res) {
	fs.open(req.body.file, 'wx', function(e, fd) { // open the file for writing if it doesn't exist
		if (fd && req.body.content) { // write the content to it
			fs.write(fd, new Buffer(req.body.content), 0, req.body.content.length, null, function(err, written) {
				res.send(!!written);
			});
		} else {
			res.send(!!e); // send success
		}
	});
{'fraction_non_alphanumeric': 0.16149818767619814, 'fraction_numerical': 0.0008054772452678212, 'mean_word_length': 3.5245901639344264, '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': '3879853', 'n_tokens_mistral': 853, 'n_tokens_neox': 817, 'n_words': 258}