|
using System;
namespace Be.Windows.Forms
{
internal sealed class FileDataBlock : DataBlock
{
long _length;
long _fileOffset;
public FileDataBlock(long fileOffset, long length)
{
_fileOffset = fileOffset;
_length = length;
}
public long FileOffset
{
get
{
return _fileOffset;
}
}
public override long Length
{
get
{
return _length;
}
}
public void SetFileOffset(long value)
{
_fileOffset = value;
}
public void RemoveBytesFromEnd(long count)
{
if (count > _length)
{
throw new ArgumentOutOfRangeException("count");
}
_length -= count;
}
public void RemoveBytesFromStart(long count)
{
if (count > _length)
{
throw new ArgumentOutOfRangeException("count");
}
_fileOffset += count;
_length -= count;
}
public override void RemoveBytes(long position, long count)
{
if (position > _length)
{
throw new ArgumentOutOfRangeException("offset");
}
if (position + count > _length)
{
throw new ArgumentOutOfRangeException("count");
}
long prefixLength = position;
long prefixFileOffset = _fileOffset;
long suffixLength = _length - count - prefixLength;
long suffixFileOffset = _fileOffset + position + count;
if (prefixLength > 0 && suffixLength > 0)
{
_fileOffset = prefixFileOffset;
_length = prefixLength;
_map.AddAfter(this, new FileDataBlock(suffixFileOffset, suffixLength));
return;
}
if (prefixLength > 0)
{
_fileOffset = prefixFileOffset;
_length = prefixLength;
}
else
{
_fileOffset = suffixFileOffset;
_length = suffixLength;
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
My name is Liron Levi and I'm developing software for fun & profit for 15 years already.