Re: [Vala] Reading last n lines from file



Le mercredi 07 octobre 2015 à 10:16 -0400, Serge Hooge a écrit :
Hello, folks.

I am currently writing a small program with Vala/ncurses and I have
suddenly found the need to read last n lines of a constantly changing
file for display in an ncurses window.

What would be the easiest way to go about it in Vala?
It doesn't look like GIO is an option without a giant data stream
kludge, but I kind of need it to create and delete some files along
the
way.

You can use a DataInputStream http://valadoc.org/#!api=gio-2.0/GLib.Dat
aInputStream and seek approximately to n * average bytes per line from
the end and read the following data with read_line. It should read
approximately n lines quite efficiently.

You can trigger the operation with a FileMonitor http://valadoc.org/#!a
pi=gio-2.0/GLib.FileMonitor

The other approach involve a subprocess that calls tail.


Cheers,
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list
-- 
Guillaume Poirier-Morency <guillaumepoiriermorency gmail com>

Étudiant au baccalauréat en Informatique à l'Université de Montréal
Développeur d'application web

Mon blog: https://arteymix.github.io
Mon projet de coopérative: https://pittoresque.github.io
Clé PGP: B1AD6EA5

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]