Create  Edit  FrontPage  Index  Search  Changes  History  RSS  Back  Login

GLib::IOChannel Diff - Ruby-GNOME2 Project Website

  • Added parts are displayed like this.
  • Deleted parts are displayed like this.

= class GLib::IOChannel

GLib::IOChannel provides portable support for files, sockets and pipes.

== Object Hierarchy

* Object
  * GLib::Boxed
    * GLib::IOChannel

== Included Modules

  * Enumerable

== Class Methods

---, mode = "r") [ {|channel|...} ]

    Creates a channel using a file. If block given, channel is closed automatically
    * filename: the file to open
    * mode: mode flags
    * Returns: the channel

--- [ {|channel|...} ]

    Opens a channel using an existing file descriptor. If block given, channel is closed automatically.
    * fd: the descriptor. (UNIX only)
    * Returns: the channel

---, mode = "r")

    Creates a channel with a file
    * filename: the file name
    * mode: the file creation flags


    Associates an existing UNIX file descriptor with an IOChannel.
    (Unix only)
    * fd: the file descriptor


     * Returns: self: ((*FIXME*))

== Instance Methods

--- fileno

    file descriptor of channel. (UNIX only)

--- to_i

    Same as GLib::IOChannel#fileno

--- read(count = nil)

    Reads count characters. If count is nil, reads to the end of file.
    * Returns: the string received, or "" if already at EOF

--- readchar

    Reads a single char, or throws an exception if at end of file.
    * Returns: the char

--- getc

    Reads a single char.
    * Returns: the char or nil if at EOF

--- readline(rs = nil)

    Reads a line from the channel. throws an exception if at end of file.
    * rs: the record separator used for line breaks
    * Returns: the line

--- gets(rs = nil)

    reads a line from the channel.
    * rs: the record separator used for line breaks
    * Returns: the line or nil if at end of file

--- each_line(rs = nil) {|line|...}

    performs block operation on each line of the file.
    * rs: the record separator used to determine line breaks
    * Returns: self

--- each(rs=nil) {|line|...}

    Same as GLib::IOChannel#each_line

--- each_char {|char|...}

    Passes each char of the file to a block.
    * Returns: self

--- write(str)

    Writes a string to the channel.
    * str: the string
    * Returns: self

--- printf(...)

    Writes a printf style string.

--- print(...)

    Prints any arguments given, or $_

--- puts(...)

    Prints arguments given, or newline if none specified.

--- putc(ch)

    Writes a char.
    * ch: the char
    * Returns: self

--- flush

    Flushes output.
    * Returns: self

--- seek(offset, type = IOChannel::SEEK_SET)

    Seeks into file.
    * offset: the offset
    * type: seek mode, for example GLib::IOChannel::SEEK_SET
    * Returns: self

--- pos=

    sets the offset from the start of the file.
    * Returns: self

--- close

    Closes the file.

--- create_watch(condition)

    creates a GLib::Source which is dispatched when condition is met.
    * condition: bitwise combination of conditions. Eg GLib::IOChannel::IN
    * Returns: the GLib::Source

--- add_watch(condition) {|channel, condition|...}

    Uses a GLib::Source to watch the IOChannel from the GTK main loop.
    The associated block should end with false to stop further watching, or
    true to continue.
    * condition: bitwise combination of conditions. eg. GLib::IOChannel::IN

    * Returns: the id of the GLib::Source created

--- buffer_size

    The buffer size of the channel

--- buffer_size=

    Sets the buffer size for the channel

--- buffer_condition

    IO_IN set if buffer has data to be read. IO_OUT set if space available to
    *Returns: GLib::IOChannel::IN if data to be read in buffer, or GLib::IOChannel::OUT if space available to write to buffer

--- flags

    The current IOChannel flags. A bitwise combination of flags. see GLib::IOChannel::FLAG_NONBLOCK

--- flags=

    Sets the flags. For example, with GLib::IOChannel::FLAG_NONBLOCK

--- buffered

    true if the channel is buffered

--- buffered=

    Enables/disables buffering

--- encoding

    The current encoding - default is 'UTF-8'

--- encoding=

    Sets the character encoding. Set to '' for binary files

--- print

     * Returns: self: ((*FIXME*))

--- printf

     * Returns: self: ((*FIXME*))

--- puts

     * Returns: self: ((*FIXME*))

--- set_buffer_size

     * Returns: self: ((*FIXME*))

--- set_buffered

     * Returns: self: ((*FIXME*))

--- set_encoding

     * Returns: self: ((*FIXME*))

--- set_flags

     * Returns: self: ((*FIXME*))

--- set_pos

     * Returns: self: ((*FIXME*))

== Constants

=== Seek constants


    Seek offset is relative to current position


    Seek offset is relative to start


    Seek offset is relative to end

=== Status constants

These are used internally to raise exceptions.


    IO error - raises a RuntimeError


    No error


    End of file - raises an EOFError


    Can perform operation again - raises a RuntimeError with "G_IO_STATUS_AGAIN"

=== Condition constants

--- IN

    There is data to read

--- OUT

    Data can be written without blocking

--- PRI

    Priority data to be written

--- ERR


--- HUP

    Hung up

--- NVAL

    Invalid request (file descriptor not open)

=== IO Flag constants

Flag operations use a bitwise combination of these.


    Append mode.


    Nonblocking mode.


    Channel is readable. Flag cannot be changed.


    Channel is writeable. Flag cannot be changed.


    Can seek in channel. Flag cannot be changed.


    Mask of all the flags


    Same GLib::IOChannel::FLAG_MASK


    Masks only the changeable bits.

== See Also

== ChangeLog

- ((<Bruce>))