WIP: Added packing of AR and TAR
This commit is contained in:
45
AMWD.Common/Packing/Tar/Utils/DataWriter.cs
Normal file
45
AMWD.Common/Packing/Tar/Utils/DataWriter.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.IO;
|
||||
using AMWD.Common.Packing.Tar.Interfaces;
|
||||
|
||||
namespace AMWD.Common.Packing.Tar.Utils
|
||||
{
|
||||
internal class DataWriter : IArchiveDataWriter
|
||||
{
|
||||
private readonly long size;
|
||||
private long remainingBytes;
|
||||
private readonly Stream stream;
|
||||
|
||||
public DataWriter(Stream data, long dataSizeInBytes)
|
||||
{
|
||||
size = dataSizeInBytes;
|
||||
remainingBytes = size;
|
||||
stream = data;
|
||||
}
|
||||
|
||||
public bool CanWrite { get; private set; } = true;
|
||||
|
||||
public int Write(byte[] buffer, int count)
|
||||
{
|
||||
if (remainingBytes == 0)
|
||||
{
|
||||
CanWrite = false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bytesToWrite;
|
||||
if (remainingBytes - count < 0)
|
||||
{
|
||||
bytesToWrite = (int)remainingBytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
bytesToWrite = count;
|
||||
}
|
||||
|
||||
stream.Write(buffer, 0, bytesToWrite);
|
||||
remainingBytes -= bytesToWrite;
|
||||
|
||||
return bytesToWrite;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user