a729206479cd9f1d3c4a295225324958e45f300a
[cinaest] / src / imdb / imdb-gzip-parser.vala
1 class IMDbGzipParser {
2         private LineParser parser;
3         private Cancellable cancellable;
4
5         public IMDbGzipParser (Cancellable? _cancellable) {
6                 cancellable = _cancellable;
7         }
8
9         public void parse (string path, LineParser? _parser) throws IOError {
10                 parser = _parser;
11
12                 var file = File.new_for_path (path);
13                 var gz_stream = new GzipInputStream (file.read (cancellable));
14                 var stream = new DataInputStream (gz_stream);
15
16                 int total_in = 0;
17                 size_t length;
18                 string line;
19                 progress (0, 0);
20                 line = stream.read_line (out length, cancellable);
21                 while (line != null) {
22                         parser.parse_line (line);
23                         line = stream.read_line (out length, cancellable);
24                         if (gz_stream.total_in () > total_in) {
25                                 total_in = (int) gz_stream.total_in ();
26                                 progress (0, total_in);
27                         }
28                 }
29         }
30
31         public signal void progress (int total, int now);
32 }