diff --git a/ArcFormats/CommonStreams.cs b/ArcFormats/CommonStreams.cs
index 57f094ba..fa0547bf 100644
--- a/ArcFormats/CommonStreams.cs
+++ b/ArcFormats/CommonStreams.cs
@@ -249,6 +249,50 @@ namespace GameRes.Formats
}
}
+ ///
+ /// Limits underlying stream to the first N bytes.
+ ///
+ public class LimitStream : InputProxyStream
+ {
+ bool m_can_seek;
+ long m_position;
+ long m_last;
+
+ public LimitStream (Stream input, long last, bool leave_open = false) : base (input, leave_open)
+ {
+ m_can_seek = input.CanSeek;
+ m_position = 0;
+ m_last = last;
+ }
+
+ public override bool CanSeek { get { return m_can_seek; } }
+ public override long Length { get { return m_last; } }
+
+ public override int Read (byte[] buffer, int offset, int count)
+ {
+ if (m_can_seek)
+ m_position = Position;
+ if (m_position >= m_last)
+ return 0;
+ count = (int)Math.Min (count, m_last - m_position);
+ int read = BaseStream.Read (buffer, offset, count);
+ m_position += read;
+ return read;
+ }
+
+ public override int ReadByte ()
+ {
+ if (m_can_seek)
+ m_position = Position;
+ if (m_position >= m_last)
+ return -1;
+ int b = BaseStream.ReadByte();
+ if (-1 != b)
+ ++m_position;
+ return b;
+ }
+ }
+
///
/// Lazily evaluated wrapper around non-seekable stream.
///
diff --git a/ArcFormats/Primel/Compression.cs b/ArcFormats/Primel/Compression.cs
index 48f48b6e..033dc7a9 100644
--- a/ArcFormats/Primel/Compression.cs
+++ b/ArcFormats/Primel/Compression.cs
@@ -354,45 +354,4 @@ namespace GameRes.Formats.Primel
}
}
}
-
- internal class LimitStream : InputProxyStream
- {
- bool m_can_seek;
- long m_position;
- long m_last;
-
- public LimitStream (Stream input, long last, bool leave_open = false) : base (input, leave_open)
- {
- m_can_seek = input.CanSeek;
- m_position = 0;
- m_last = last;
- }
-
- public override bool CanSeek { get { return m_can_seek; } }
- public override long Length { get { return m_last; } }
-
- public override int Read (byte[] buffer, int offset, int count)
- {
- if (m_can_seek)
- m_position = Position;
- if (m_position >= m_last)
- return 0;
- count = (int)Math.Min (count, m_last - m_position);
- int read = BaseStream.Read (buffer, offset, count);
- m_position += read;
- return read;
- }
-
- public override int ReadByte ()
- {
- if (m_can_seek)
- m_position = Position;
- if (m_position >= m_last)
- return -1;
- int b = BaseStream.ReadByte();
- if (-1 != b)
- ++m_position;
- return b;
- }
- }
}