UNIX dognails

pull/5/merge
Ogoun 6 months ago
parent d31f89f734
commit 640879c3bd

@ -9,19 +9,39 @@ namespace ZeroLevel.Services.FileSystem
: IDisposable : IDisposable
{ {
private MemoryMappedFile _mmf; private MemoryMappedFile _mmf;
private FileStream _stream;
private readonly long _fileLength; private readonly long _fileLength;
public long FileLength => _fileLength; public long FileLength => _fileLength;
public ParallelFileReader(string filePath) public ParallelFileReader(string filePath)
{ {
_fileLength = new FileInfo(filePath).Length; _fileLength = new FileInfo(filePath).Length;
_mmf = MemoryMappedFile.CreateFromFile(filePath, FileMode.Open, Guid.NewGuid().ToString(), 0, MemoryMappedFileAccess.Read); try
{
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
_stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
_mmf = MemoryMappedFile.CreateFromFile(_stream, null, _stream.Length, MemoryMappedFileAccess.Read, HandleInheritability.None, true);
}
else
{
//_stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
//_mmf = MemoryMappedFile.CreateFromFile(_stream, null, _stream.Length, MemoryMappedFileAccess.Read, HandleInheritability.None, true);
_mmf = MemoryMappedFile.CreateFromFile(filePath, FileMode.Open, Guid.NewGuid().ToString(), 0, MemoryMappedFileAccess.Read);
}
}
catch (Exception ex)
{
Log.Error(ex, $"Fault to create MMF for {filePath}");
}
//_stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
} }
public IViewAccessor GetAccessor(long offset) public IViewAccessor GetAccessor(long offset)
{ {
var length = _fileLength - offset; var length = _fileLength - offset;
return new MMFViewAccessor(_mmf.CreateViewStream(offset, length, MemoryMappedFileAccess.Read), offset); return new MMFViewAccessor(_mmf.CreateViewStream(offset, length, MemoryMappedFileAccess.Read), offset);
//return new StreamVewAccessor(_stream);
} }
public IViewAccessor GetAccessor(long offset, int length) public IViewAccessor GetAccessor(long offset, int length)
@ -30,12 +50,14 @@ namespace ZeroLevel.Services.FileSystem
{ {
throw new OutOfMemoryException($"Offset + Length ({offset + length}) more than file length ({_fileLength})"); throw new OutOfMemoryException($"Offset + Length ({offset + length}) more than file length ({_fileLength})");
} }
//return new StreamVewAccessor(_stream);
return new MMFViewAccessor(_mmf.CreateViewStream(offset, length, MemoryMappedFileAccess.Read), offset); return new MMFViewAccessor(_mmf.CreateViewStream(offset, length, MemoryMappedFileAccess.Read), offset);
} }
public void Dispose() public void Dispose()
{ {
_mmf?.Dispose(); _mmf?.Dispose();
_stream?.Dispose();
} }
} }
} }

File diff suppressed because one or more lines are too long

@ -18,11 +18,11 @@ namespace ZeroLevel.Services.Web
{ {
if (i % 2 == 0) if (i % 2 == 0)
{ {
result.Add(i + "-" + result[i - 2]); result.Add($"{i}-{result[i - 2]}");
} }
else else
{ {
result.Add(new string(result[i - 2].Reverse().ToArray()) + "-" + i); result.Add($"{new string(result[i - 2].Reverse().ToArray())}-{i}");
} }
} }
return result; return result;

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<Description>Multi-tool <Description>Multi-tool
</Description> </Description>
<Authors>ogoun</Authors> <Authors>ogoun</Authors>

Loading…
Cancel
Save

Powered by TurnKey Linux.