Added ability to arbitrarily get data from a File by offset and length (without having to read the ENTIRE file from the source data); this must be supported by your DataFormat's implementation of DataRequest though
This commit is contained in:
parent
eca27273f3
commit
a3fba29ef9
@ -2,13 +2,23 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UniversalEditor.IO;
|
||||
|
||||
namespace UniversalEditor.ObjectModels.FileSystem
|
||||
{
|
||||
public delegate void DataRequestEventHandler(object sender, DataRequestEventArgs e);
|
||||
public class DataRequestEventArgs : EventArgs
|
||||
{
|
||||
private byte[] mvarData = null;
|
||||
public byte[] Data { get { return mvarData; } set { mvarData = value; } }
|
||||
}
|
||||
public delegate void DataRequestEventHandler(object sender, DataRequestEventArgs e);
|
||||
public class DataRequestEventArgs : EventArgs
|
||||
{
|
||||
private byte[] mvarData = null;
|
||||
public byte[] Data { get { return mvarData; } set { mvarData = value; } }
|
||||
|
||||
private Reader mvarReader = null;
|
||||
public Reader Reader { get { return mvarReader; } set { mvarReader = value; } }
|
||||
|
||||
private long mvarOffset = 0;
|
||||
public long Offset { get { return mvarOffset; } set { mvarOffset = value; } }
|
||||
|
||||
private long mvarLength = 0;
|
||||
public long Length { get { return mvarLength; } set { mvarLength = value; } }
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +99,18 @@ namespace UniversalEditor.ObjectModels.FileSystem
|
||||
{
|
||||
DataRequestEventArgs e = new DataRequestEventArgs();
|
||||
DataRequest(this, e);
|
||||
mvarData = e.Data;
|
||||
if (e.Data == null && e.Reader == null)
|
||||
{
|
||||
Console.WriteLine("DataRequest: " + mvarName + ": Data is not represented as a byte array or Reader");
|
||||
}
|
||||
else if (e.Data != null)
|
||||
{
|
||||
mvarData = e.Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("DataRequest: " + mvarName + ": Data is not represented as a byte array; please use GetData() method");
|
||||
}
|
||||
}
|
||||
return mvarData;
|
||||
}
|
||||
@ -109,6 +120,29 @@ namespace UniversalEditor.ObjectModels.FileSystem
|
||||
mvarData = data;
|
||||
}
|
||||
|
||||
public byte[] GetData(long offset, long length)
|
||||
{
|
||||
DataRequestEventArgs e = new DataRequestEventArgs();
|
||||
DataRequest(this, e);
|
||||
if (e.Data != null)
|
||||
{
|
||||
long realLength = Math.Min(length, e.Data.Length);
|
||||
byte[] data = new byte[realLength];
|
||||
Array.Copy(e.Data, 0, data, 0, realLength);
|
||||
return data;
|
||||
}
|
||||
else if (e.Reader != null)
|
||||
{
|
||||
long realLength = Math.Min(length, e.Length);
|
||||
e.Reader.Seek(e.Offset + offset, IO.SeekOrigin.Begin);
|
||||
byte[] data = e.Reader.ReadBytes(length);
|
||||
return data;
|
||||
}
|
||||
|
||||
Console.WriteLine("DataRequest: " + mvarName + ": Data is not represented as a byte array or Reader");
|
||||
return null;
|
||||
}
|
||||
|
||||
private System.IO.Stream mvarStream = null;
|
||||
public System.IO.Stream GetDataAsStream()
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user