mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-09-24 15:55:05 +00:00
Merge pull request #8 from TheRogueArchivist/streamdatalock
Add lock for reading data from stream
This commit is contained in:
@@ -29,6 +29,11 @@ namespace SabreTools.Serialization.Wrappers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected DataSource _dataSource = DataSource.UNKNOWN;
|
protected DataSource _dataSource = DataSource.UNKNOWN;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Lock object for reading from the source
|
||||||
|
/// </summary>
|
||||||
|
private readonly object _streamDataLock = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Source byte array data
|
/// Source byte array data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -193,12 +198,15 @@ namespace SabreTools.Serialization.Wrappers
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case DataSource.Stream:
|
case DataSource.Stream:
|
||||||
|
lock (_streamDataLock)
|
||||||
|
{
|
||||||
long currentLocation = _streamData!.Position;
|
long currentLocation = _streamData!.Position;
|
||||||
_streamData.Seek(position, SeekOrigin.Begin);
|
_streamData.Seek(position, SeekOrigin.Begin);
|
||||||
sectionData = _streamData.ReadBytes(length);
|
sectionData = _streamData.ReadBytes(length);
|
||||||
_streamData.Seek(currentLocation, SeekOrigin.Begin);
|
_streamData.Seek(currentLocation, SeekOrigin.Begin);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return sectionData;
|
return sectionData;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user