in AdlsDotNetSDK/AdlsInputStream.cs [308:348]
public override long Seek(long offset, SeekOrigin origin)
{
if (IpStreamLog.IsTraceEnabled)
{
IpStreamLog.Trace($"ADLFileInputStream, Seek to offset {offset} from {Enum.GetName(typeof(SeekOrigin), origin)} for file {Filename} for client {Client.ClientId}");
}
if (_isDisposed)
{
throw new ObjectDisposedException("Stream is disposed");
}
long prevFilePointer = FilePointer;//Store previous Filepointer
if (origin == SeekOrigin.Current)
{
FilePointer += offset;
}
else if (origin == SeekOrigin.Begin)
{
FilePointer = offset;
}
else//SeekOrigin.End
{
FilePointer = Entry.Length + offset;
}
if (FilePointer < 0)
{
FilePointer = prevFilePointer;
throw new IOException("Cannot seek before the begining of the file");
}
if (FilePointer > Entry.Length)
{
FilePointer = prevFilePointer;
throw new IOException("Cannot seek beyond the end of the file");
}
long diffFilePointer = FilePointer - prevFilePointer;//Calculate the offset between current pointer and new pointer
BufferPointer += diffFilePointer;//Update the BufferPointer based on how much the FilePointer moved
if (BufferPointer < 0 || BufferPointer >= BufferSize)
{
BufferPointer = BufferSize = 0;//Current Filepointer points to data which does not exist in buffer
}
return FilePointer;
}