Files
sharpcompress/SharpCompress/IO/ReadOnlySubStream.cs

94 lines
2.3 KiB
C#
Raw Normal View History

2013-04-07 10:58:58 +01:00
using System.IO;
namespace SharpCompress.IO
{
internal class ReadOnlySubStream : Stream
{
public ReadOnlySubStream(Stream stream, long bytesToRead)
2013-08-11 09:45:46 +01:00
: this(stream, null, bytesToRead)
{
}
public ReadOnlySubStream(Stream stream, long? origin, long bytesToRead)
2013-04-07 10:58:58 +01:00
{
Stream = stream;
2013-08-11 09:45:46 +01:00
if (origin != null)
{
stream.Position = origin.Value;
}
2013-04-07 10:58:58 +01:00
BytesLeftToRead = bytesToRead;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
//Stream.Dispose();
}
}
2013-04-28 12:32:55 +01:00
private long BytesLeftToRead { get; set; }
2013-04-07 10:58:58 +01:00
2013-04-28 12:32:55 +01:00
public Stream Stream { get; private set; }
2013-04-07 10:58:58 +01:00
public override bool CanRead
{
2013-04-28 12:32:55 +01:00
get { return true; }
2013-04-07 10:58:58 +01:00
}
public override bool CanSeek
{
2013-04-28 12:32:55 +01:00
get { return false; }
2013-04-07 10:58:58 +01:00
}
public override bool CanWrite
{
2013-04-28 12:32:55 +01:00
get { return false; }
2013-04-07 10:58:58 +01:00
}
public override void Flush()
{
throw new System.NotSupportedException();
2013-04-07 10:58:58 +01:00
}
public override long Length
{
get { throw new System.NotSupportedException(); }
2013-04-07 10:58:58 +01:00
}
public override long Position
{
get { throw new System.NotSupportedException(); }
set { throw new System.NotSupportedException(); }
2013-04-07 10:58:58 +01:00
}
public override int Read(byte[] buffer, int offset, int count)
{
if (BytesLeftToRead < count)
{
2013-08-11 09:45:46 +01:00
count = (int)BytesLeftToRead;
2013-04-07 10:58:58 +01:00
}
int read = Stream.Read(buffer, offset, count);
if (read > 0)
{
BytesLeftToRead -= read;
}
return read;
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new System.NotSupportedException();
2013-04-07 10:58:58 +01:00
}
public override void SetLength(long value)
{
throw new System.NotSupportedException();
2013-04-07 10:58:58 +01:00
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new System.NotSupportedException();
2013-04-07 10:58:58 +01:00
}
}
2013-04-28 12:32:55 +01:00
}