<commit_before>var nodecr = require('nodecr');
var http = require("http");
var url = require('url');
var fs = require('fs');

function start() {
	function onRequest(request, response) {
		var body = "";
		request.on("data", function (chunk) {
			body += chunk;
		});
		request.on("end", function() {
			console.log("\n" + (new Date()) + ": Request received.");
			if (body != "") {
				body = body.replace(/^data:image\/jpeg;base64,/,"");
				fs.writeFile("temp/temp.jpg", body, 'base64', function(err) {
					if (err) {
						console.log((new Date()) + ": " + err);
					}
				});
			}
			nodecr.process("temp/temp.jpg", function(err, text) {
				if (err) {
					console.log("Tesseract error!");
					response.writeHead(500, {"Content-Type": "text/plain", "Access-Control-Allow-Origin": "*"});
					response.write("Tesseract error");
					response.end();
					fs.unlink("temp/temp.jpg", function(err) {
						if (err) {
							console.log((new Date()) + ": Couldn't delete temp.jpg!");
						} else {
							console.log((new Date()) + ": temp.jpg deleted");
						}
					});
				} else {
					console.log("Success: %s", text);
					response.writeHead(200, {"Content-Type": "text/plain", "Access-Control-Allow-Origin": "*"});
					response.write(text.substring(0, text.length));
					response.end();
					fs.unlink("temp/temp.jpg", function(err) {
						if (err) {
							console.log((new Date()) + ": Couldn't delete temp.jpg!");
						} else {
							console.log((new Date()) + ": temp.jpg deleted");
						}
					});
				}
			});
		});
	}
	http.createServer(onRequest).listen(8888);
	console.log((new Date()) + ": Server has started.");
}

exports.start = start;<commit_msg>more temp files for multiple requests at same time<commit_after>var nodecr = require("nodecr");
var http = require("http");
var fs = require("fs");

function start() {
	function onRequest(request, response) {
		var body = "";
		request.on("data", function (chunk) {
			body += chunk;
		});
		request.on("end", function() {
			console.log((new Date()) + ": Request received.\n");
			
			if (body != "") {
				body = body.replace(/^data:image\/jpeg;base64,/,"");
				var random = Math.floor(Math.random() * 100000);
				
				fs.writeFile("temp/temp" + random + ".jpg", body, 'base64', function(err) {
					if (err) {
						console.log("\n" + (new Date()) + ": " + err);
					} else {
						console.log("\n" + (new Date()) + ": temp%d.jpg created", random);
					}
				});
				
				nodecr.process("temp/temp" + random + ".jpg", function(err, text) {
					if (err) {
						console.log("Tesseract error!");
						
						response.writeHead(500, {"Content-Type": "text/plain", "Access-Control-Allow-Origin": "*"});
						response.write("Tesseract error");
						response.end();
						
						fs.unlink("temp/temp" + random + ".jpg", function(err) {
							if (err) {
								console.log((new Date()) + ": Couldn't delete temp%d.jpg!", random);
							} else {
								console.log((new Date()) + ": temp%d.jpg deleted", random);
							}
						});
					} else {
						console.log("\nSuccess: %s", text);
						
						response.writeHead(200, {"Content-Type": "text/plain", "Access-Control-Allow-Origin": "*"});
						response.write(text.substring(0, text.length));
						response.end();
						
						fs.unlink("temp/temp" + random + ".jpg", function(err) {
							if (err) {
								console.log((new Date()) + ": Couldn't delete temp%d.jpg!", random);
							} else {
								console.log((new Date()) + ": temp%d.jpg deleted", random);
							}
						});
					}
				});
			} else {
				console.log((new Date()) + ": No body found!");
				
				response.writeHead(500, {"Content-Type": "text/plain", "Access-Control-Allow-Origin": "*"});
				response.write("No body found!");
				response.end();
			}
		});
	}
	
	http.createServer(onRequest).listen(8888);
	console.log((new Date()) + ": Server has started.");
}

exports.start = start;
{'fraction_non_alphanumeric': 0.2123076923076923, 'fraction_numerical': 0.01, 'mean_word_length': 2.794747081712062, 'pattern_counts': {'":': 26, '<': 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': '294944', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1255, 'n_words': 251}