1
0

WIP: Added packing of AR and TAR

This commit is contained in:
2023-03-13 10:08:50 +01:00
parent e8a1378f60
commit 7cd5358ac8
18 changed files with 2071 additions and 4 deletions

View 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;
}
}
}