Files
sharpcompress/SharpCompress/Common/Tar/TarReadOnlySubStream.cs

99 lines
2.6 KiB
C#
Raw Permalink Normal View History

2013-04-07 10:58:58 +01:00
using System.IO;
namespace SharpCompress.Common.Tar
{
internal class TarReadOnlySubStream : Stream
{
private int amountRead;
public TarReadOnlySubStream(Stream stream, long bytesToRead)
{
this.Stream = stream;
this.BytesLeftToRead = bytesToRead;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
2013-04-28 12:32:55 +01:00
int skipBytes = this.amountRead%512;
2013-04-07 10:58:58 +01:00
if (skipBytes == 0)
{
return;
}
skipBytes = 512 - skipBytes;
if (skipBytes == 0)
{
return;
}
var buffer = new byte[skipBytes];
this.Stream.ReadFully(buffer);
}
}
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.NotImplementedException();
}
public override long Length
{
2013-04-28 12:32:55 +01:00
get { throw new System.NotImplementedException(); }
2013-04-07 10:58:58 +01:00
}
public override long Position
{
2013-04-28 12:32:55 +01:00
get { throw new System.NotImplementedException(); }
set { throw new System.NotImplementedException(); }
2013-04-07 10:58:58 +01:00
}
public override int Read(byte[] buffer, int offset, int count)
{
if (this.BytesLeftToRead < count)
{
2013-04-28 12:32:55 +01:00
count = (int) this.BytesLeftToRead;
2013-04-07 10:58:58 +01:00
}
int read = this.Stream.Read(buffer, offset, count);
if (read > 0)
{
this.BytesLeftToRead -= read;
this.amountRead += read;
}
return read;
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new System.NotImplementedException();
}
public override void SetLength(long value)
{
throw new System.NotImplementedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new System.NotImplementedException();
}
}
2013-04-28 12:32:55 +01:00
}