login about faq

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.

asked Jul 08 '17 at 05:59

Rajkumar%20G's gravatar image

Rajkumar G

Thanks! The bug in LastNLines was discovered after the v9.5.0.68 release. I can create an ActiveX pre-release of .69 and post it here later today.


answered Jul 08 '17 at 07:12

chilkat's gravatar image

chilkat ♦♦


answered Jul 08 '17 at 07:30

chilkat's gravatar image

chilkat ♦♦

Thanks for the reply. I have downloaded and used the latest Chilkat .NET library (https://chilkatdownload.com/ for C# and I am still getting the same problem..

(Jul 08 '17 at 09:41) Rajkumar G

Can you please apply the fix and create a new win32 build to support C# & Visual Studio 2015?

(Jul 09 '17 at 01:27) Rajkumar G

I was mistaken in that the bug I mentioned was actually in the Chilkat.StringBuilder.LastNLines method. (You wouldn't use StringBuilder to load a 5GB file into memory..)

(Jul 11 '17 at 10:48) chilkat ♦♦

For the FileSeek method, passing SeekOrigin.End is only valid if in fact SeekOrigin.End equals 2. Just pass the number 2. Chilkat is cross-platform/cross-language, so we can't use "SeekOrigin.End" because it doesn't apply across languages. We really need a specific number (i.e. 2 in this case).

Also, I don't quite understand the logic of using a loop. Just seek -1024 from the end if that's what you want..


answered Jul 11 '17 at 10:51

chilkat's gravatar image

chilkat ♦♦

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Jul 08 '17 at 05:59

Seen: 3,709 times

Last updated: Jul 11 '17 at 10:51

powered by OSQA