I need to read only the last n lines from the file using Chilkat library (FileAccess) - https://www.chilkatsoft.com/refdoc/xCkFileAccessRef.html. Because the file size would be large(upto 5GB). I can able to read the last few records by using FileStream. But I want to do the same kind of parsing in Chilkat.
Parsing last few records in FileStream:
int sizeOfChar = 1;
Encoding _selectedEncoding = Encoding.ASCII;
using (FileStream fs = new FileStream(filePath, FileMode.Open))
{
long endPosition = 1024;
for (long position = sizeOfChar; position < endPosition; position += sizeOfChar)
{
fs.Seek(-position, SeekOrigin.End);
}
byte[] extractedBuffer = new byte[fs.Length - fs.Position];
fs.Read(extractedBuffer, 0, extractedBuffer.Length);
string strTokens = _selectedEncoding.GetString(extractedBuffer);
}
This code is working fine as expected and returns last few lines. I have tried to achieve the same using Chilkat FileAccess class and it returns only empty array.
Parsing last few records in Chilkat.FileAccess:
int sizeOfChar = 1;
Chilkat.FileAccess fa = new Chilkat.FileAccess();
bool isFileOpened = fa.FileOpen(filePath, 0x80000000, 0x00000001, 4, 0x00000080);
int endPosition = 1024;
for (int position = sizeOfChar; position < endPosition; position += sizeOfChar)
{
fa.FileSeek(-position, (int)SeekOrigin.End);
}
byte[] extractedBuffer = fa.FileRead(endPosition);
string strTokens = _selectedEncoding.GetString(extractedBuffer);
I can able to fetch first few lines using Chilkat but I want to get last few lines. Please check the above code block and anyone help me to parse the last few lines using Chilkat.