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