Am Mittwoch, den 02.12.2009, 04:27 -0700 schrieb Mark Dewey:
> Julian Andres Klode wrote:
> > Am Mittwoch, den 02.12.2009, 03:29 -0700 schrieb Mark Dewey:
> >> Also, are there any libraries for Vala that deal with tar files? I know
> >> Python has some that worked great (simply called tar—they took care of
> >> gzip files, too).
> > I am working on bindings for libarchive, which allows you to read a
> > number of archive formats and create archives, its website is:
> >   http://code.google.com/p/libarchive/
> 
> Awesome. Thanks for letting me know! I'll have to study up on the
> documentation to prep myself for its arrival.

I attached a short example for reading out an archive and sent this to
the mailing list again, as it may be of interest to others as well.


-- 
Julian Andres Klode  - Debian Developer, Ubuntu Member

See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/.

/* archive.vala - Example for using the libarchive bindings in Vala.
 *
 * Copyright (C) 2009 Julian Andres Klode <[email protected]>
 *
 * Copying and distribution of this file, with or without modification,
 * are permitted in any medium without royalty provided the copyright
 * notice and this notice are preserved.  This file is offered as-is,
 * without any warranty.
 */
using Archive;
using Posix;


void main(string[] args) {

    // Create a new archive object for reading
	Read archive = new Read();
    // A buffer which will hold read data
	char buf[4096];
    // The entry which will be read from the archive.
	weak Entry e;

    // First argument is the archive file.
    if (args.length != 2)
        error("Usage: %s <archive>", args[0]);

    // Enable all supported compression formats
	archive.support_compression_all();
    // Enable all supported archive formats.
	archive.support_format_all();

    // Open the file, if it fails exit
	if (archive.open_filename(args[1], 4096) != Result.OK) 
		error("%s", archive.error_string());

	
	while(archive.next_header(out e) == Result.OK) {		
		if (S_ISDIR(e.mode()))
			print("DIR:  %s\n", e.pathname());
		else {
			print("FILE: %s\n", e.pathname());
        }

        // Read the times of the file
        print("MTIME: %li\n", e.mtime());
		print("CTIME: %li\n", e.ctime());
		print("ATIME: %li\n", e.atime());

        // Read out files ending in .txt and README files, into the buffer buf.
        if (e.pathname().has_suffix(".txt") || e.pathname().has_suffix("README"))
            while(archive.read_data(buf, 4096) != 0)
                // Print the contents of buf, indented with a tab.
                print("\t%s", ((string)buf).replace("\n", "\n\t"));
        print("\n");
	}
    
}
_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to