stringbuilder is faster than string but something is still off, most files dont have barely any content

This commit is contained in:
ti_mo
2026-02-22 00:52:43 +01:00
parent 1788f33c2f
commit 5671a7aac8
+17 -6
View File
@@ -42,7 +42,7 @@ static class DataExtractor
static class DataHandler
{
public const string OutputDir = "./output";
public const string OutputDir = "output";
public static void Parse(string data)
{
@@ -54,7 +54,16 @@ static class DataHandler
if (parsed.Name.Length == 0 || parsed.Length == 0 || parsed.Content.Length == 0) return;
var newPath = Path.Combine(OutputDir, parsed.Name);
var processPath = Path.GetDirectoryName(Environment.ProcessPath);
if (processPath == null) return;
var outputDir = Path.Combine(processPath, OutputDir);
var newPath = Path.Combine(outputDir, parsed.Name);
if (newPath == parsed.Name)
{
newPath = outputDir + Path.DirectorySeparatorChar + parsed.Name.TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
} // DO NOT WRITE SOMEWHERE ELSE THAN OUTPUT DIR
var fi = new FileInfo(newPath);
var dir = Path.GetDirectoryName(newPath) ?? OutputDir;
var di = new DirectoryInfo(dir);
@@ -94,12 +103,13 @@ internal class Server
{
if(!_listener.Pending()) continue;
var peer = _listener.AcceptTcpClient();
var stream = peer.GetStream();
using var peer = _listener.AcceptTcpClient();
using var stream = peer.GetStream();
Console.WriteLine($"Connected to Peer: {peer.Client.RemoteEndPoint}");
while (GetState(peer) == TcpState.Established)
{
StringBuilder sb = new();
var buffer = "";
try
@@ -120,14 +130,15 @@ internal class Server
var recvCount = stream.Read(recvBytes);
if(recvCount <= 0) continue;
// TODO: for is to heavy
for (var i = 0; i < recvCount; i++) buffer += (char)recvBytes[i];
// TODO: for and string are to heavy
sb.Append(Encoding.UTF8.GetString(recvBytes));
availableBytes -= recvCount;
}
}
}
catch (Exception ex) { Console.WriteLine(ex.Message); }
buffer = sb.ToString();
if(buffer.Length == 0) continue;
foreach (var b in buffer.Split("\r\n\r\n"))