don't limit MemoryFileSource to just a byte[] array

This commit is contained in:
Michael Becker 2020-09-09 06:03:40 -04:00
parent f425651eb2
commit 275f9e7e59
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7

View File

@ -20,33 +20,38 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using UniversalEditor.Accessors;
namespace UniversalEditor.ObjectModels.FileSystem.FileSources
{
/// <summary>
/// Provides a <see cref="FileSource" /> for retrieving file data from a <see cref="byte" /> array.
/// Provides a <see cref="FileSource" /> for retrieving file data from a <see cref="MemoryAccessor" />.
/// </summary>
public class MemoryFileSource : FileSource
{
private byte[] mvarData = null;
public byte[] Data { get { return mvarData; } set { mvarData = value; } }
public MemoryAccessor Data { get; set; } = null;
public MemoryFileSource(byte[] data)
{
mvarData = data;
Data = new MemoryAccessor(data);
}
public MemoryFileSource(MemoryAccessor data)
{
Data = data;
}
public override byte[] GetDataInternal(long offset, long length)
{
long realLength = Math.Min(length, mvarData.Length);
long realLength = Math.Min(length, Data.Length);
byte[] realData = Data.ToArray();
byte[] data = new byte[realLength];
Array.Copy(mvarData, offset, data, 0, realLength);
Array.Copy(realData, offset, data, 0, realLength);
return data;
}
public override long GetLength()
{
return mvarData.Length;
return Data.Length;
}
}
}