mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-23 05:35:34 +08:00
(LimitStream): added 'Fill' option.
fills stream with zeroes if underlying stream has less length than requested.
This commit is contained in:
parent
d35f790994
commit
64e1ae3946
@ -249,6 +249,12 @@ namespace GameRes.Formats
|
||||
}
|
||||
}
|
||||
|
||||
public enum StreamOption
|
||||
{
|
||||
None,
|
||||
Fill,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Limits underlying stream to the first N bytes.
|
||||
/// </summary>
|
||||
@ -257,6 +263,7 @@ namespace GameRes.Formats
|
||||
bool m_can_seek;
|
||||
long m_position;
|
||||
long m_last;
|
||||
bool m_fill;
|
||||
|
||||
public LimitStream (Stream input, long last, bool leave_open = false) : base (input, leave_open)
|
||||
{
|
||||
@ -265,6 +272,20 @@ namespace GameRes.Formats
|
||||
m_last = last;
|
||||
}
|
||||
|
||||
public LimitStream (Stream input, long last, StreamOption option, bool leave_open = false)
|
||||
: this (input, last, leave_open)
|
||||
{
|
||||
if (StreamOption.Fill == option)
|
||||
{
|
||||
if (m_can_seek && input.Length < m_last)
|
||||
{
|
||||
input.Position = m_position;
|
||||
m_can_seek = false;
|
||||
}
|
||||
m_fill = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanSeek { get { return m_can_seek; } }
|
||||
public override long Length { get { return m_last; } }
|
||||
|
||||
@ -276,6 +297,13 @@ namespace GameRes.Formats
|
||||
return 0;
|
||||
count = (int)Math.Min (count, m_last - m_position);
|
||||
int read = BaseStream.Read (buffer, offset, count);
|
||||
if (m_fill)
|
||||
{
|
||||
while (read < count)
|
||||
{
|
||||
buffer[read++] = 0;
|
||||
}
|
||||
}
|
||||
m_position += read;
|
||||
return read;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user