Fix: memory usage
This commit is contained in:
parent
bee08f34e6
commit
e8b7b8408c
@ -3,12 +3,14 @@ namespace PacketIO;
|
|||||||
public class PacketFile : IPacketFile
|
public class PacketFile : IPacketFile
|
||||||
{
|
{
|
||||||
private string fileName;
|
private string fileName;
|
||||||
|
private TempFile? tempFile;
|
||||||
private Stream stream;
|
private Stream stream;
|
||||||
|
|
||||||
public PacketFile(string fileName)
|
public PacketFile(string fileName)
|
||||||
{
|
{
|
||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
this.stream = new MemoryStream();
|
this.tempFile = new TempFile();
|
||||||
|
this.stream = tempFile.Open(FileMode.Open);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PacketFile(string fileName, Stream stream)
|
public PacketFile(string fileName, Stream stream)
|
||||||
@ -56,5 +58,9 @@ public class PacketFile : IPacketFile
|
|||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
this.stream.Dispose();
|
this.stream.Dispose();
|
||||||
|
if (this.tempFile is object)
|
||||||
|
{
|
||||||
|
this.tempFile.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
ProtocolLib/PacketIO/TempFile.cs
Normal file
21
ProtocolLib/PacketIO/TempFile.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
namespace PacketIO;
|
||||||
|
|
||||||
|
public class TempFile : IDisposable
|
||||||
|
{
|
||||||
|
public string FileName { get; }
|
||||||
|
|
||||||
|
public TempFile()
|
||||||
|
{
|
||||||
|
FileName = Path.GetTempFileName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream Open(FileMode mode)
|
||||||
|
{
|
||||||
|
return new FileStream(FileName, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
File.Delete(FileName);
|
||||||
|
}
|
||||||
|
}
|
25
ProtocolLib/ProtocolLib.sln
Normal file
25
ProtocolLib/ProtocolLib.sln
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.5.002.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProtocolLib", "ProtocolLib.csproj", "{BB1F2133-E83C-4975-A685-D2DCE2FC24C9}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{BB1F2133-E83C-4975-A685-D2DCE2FC24C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{BB1F2133-E83C-4975-A685-D2DCE2FC24C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{BB1F2133-E83C-4975-A685-D2DCE2FC24C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{BB1F2133-E83C-4975-A685-D2DCE2FC24C9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {AD8CE391-A853-498C-A2E6-7A83701164D4}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
Loading…
Reference in New Issue
Block a user