A virtual file system or virtual filesystem switch is an abstraction layer on top of a more concrete file system. The purpose of a VFS is to allow client applications to access different types of concrete file systems in a uniform way...
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...
that sits at the right level in the library stack. The goal is to overcome the shortcomings of GnomeVFS and provide an API that is so good that developers prefer it over raw POSIX
POSIX
POSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...
GLib is a cross-platform software utility library that began as part of the GTK+ project. However, before releasing version 2 of GTK+, the project's developers decided to separate non-GUI-specific code from the GTK+ platform, thus creating GLib as a separate product...
A virtual file system or virtual filesystem switch is an abstraction layer on top of a more concrete file system. The purpose of a VFS is to allow client applications to access different types of concrete file systems in a uniform way...
which allows applications to access local and remote files with a single consistent API.
Features
The abstract file system model of GIO consists of a number of interfaces and base classes for I/O and files.
There is a number of stream classes, similar to the input and output stream hierarchies that can be found in frameworks like Java.
There are interfaces related to applications and the types of files they handle.
There is a framework for storing and retrieving application settings.
There is support for network programming, including name resolution, lowlevel socket APIs and highlevel client and server helper classes.
There is support for connecting to D-Bus, sending and receiving messages, owning and watching bus names, and making objects available on the bus.
Beyond these, GIO provides facilities for file monitoring, asynchronous I/O and filename completion. In addition to the interfaces, GIO provides implementations for the local case. Implementations for various network file systems are provided by the GVFS package as loadable modules.
Example
A simple example illustrating local file handling using GIO in C:
The above program takes a filename as an argument at runtime, prints its content-type and size, and if the input file is text-based, prints its contents too.
To compile the above program in Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...
The GNU Compiler Collection is a compiler system produced by the GNU Project supporting various programming languages. GCC is a key component of the GNU toolchain...
pkg-config is computer software that provides a unified interface for querying installed libraries for the purpose of compiling software from its source code. pkg-config was originally designed for Linux but is now also available for the various BSDs, Microsoft Windows, Mac OS X, and Solaris.It...
, use:
gcc -Wall -g gio-example.c -o gio-example $(pkg-config --cflags --libs gio-2.0)
assuming the source file is gio-example.c.
To execute the output file, use:
./gio-example filename
External links