Initial commit: Nix WSL Wrapper project with DDD, Clean Code, and tests

This commit is contained in:
Marek Novák
2026-07-01 02:04:43 +02:00
commit 161eb7d387
22 changed files with 932 additions and 0 deletions
@@ -0,0 +1,44 @@
using System;
using System.IO;
using NixWslWrapper.Core.Interfaces;
namespace NixWslWrapper.Infrastructure.IO
{
public class ThreadedStreamCopier : IStreamCopier
{
private readonly int _bufferSize;
public ThreadedStreamCopier(int bufferSize = 8192)
{
if (bufferSize <= 0)
throw new ArgumentOutOfRangeException(nameof(bufferSize), "Buffer size must be positive.");
_bufferSize = bufferSize;
}
public void Copy(Stream input, Stream output)
{
byte[] buffer = new byte[_bufferSize];
int read;
try
{
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, read);
output.Flush();
}
}
catch (IOException)
{
// Clean exit when stream is closed or process terminates
}
catch (ObjectDisposedException)
{
// Clean exit when streams are disposed
}
catch (Exception)
{
// General catch to ensure thread doesn't crash the host process
}
}
}
}