NAME

EWS::fileIO -- object-oriented class for file I/O.


SYNOPSIS

 use EWS::fileIO;

 $fileIO = new EWS::global(-debug => 0, 
                           -io    => $baseIO, 
                           -file  => $fileIOFileName,
                           -mode  => '<');

 $fileIO->open($fileIOFileName, '<') or die "Unable to open $fileIOFileName.";
 $fileIO->close;

 $fileIO->write($buffer, $buffersize) or die "Unable to write buffer.";
 $fileIO->writeln($buffer);
 
 ($buffer, $size) = $fileIO->read($buffer, $size);
 $buffer = $fileIO->readln;

 while (! $fileIO->eof){ ... };
 
 $fileIO->flock(LOCK_EX) or die "Unable to obtain an exclusive file lock.";
 $fileIO->flock(LOCK_UN);
 
 @bufferList = $fileIO->load;
 
 $position = $fileIO->tell;
 $fileIO->seek(0, $position) or die "Unable to seek to $position.";
 
 %fileStat = $fileIO->stat;

 $fileIO->truncate($position) or die "Unable to truncate file to $position.";

 $fileIO->umask(O644);

DESCRIPTION

EWS::fileIO provides object-oriented input/output to locally mounted disk files. EWS::fileIO is a class wrapper around the 'class-less' perl file i/o functions. The class supports a single file which can be automatically opened with new when the class is instantiated (created), or can be opened with the open method. All class methods apply to the file handle created with the open method.

PUBLIC METHODS

new

$fileIO = new EWS::fileIO(%parameters);

    Enter:
      %parameters = parameter hash (see below).
    Exit:
      returns a blessed reference to a new fileIO object.

    parameters are of the form:

      -arg => value

    acceptable values are:
      -bufsize   => size of buffer for read/write (default=128).
      -debug     => 1 = debug messages
      -file      => path to file.
      -io        => baseIO object
      -mode      => '<', '>', '>>' (default='<').
      -procutils => procUtils object.
      -timeout   => operation timeout in seconds (default=120).
      -type      => 0 = text, 1 = binary (default=0).

close

Close the file object.

    Enter:
      none.
    Exit:
      none.

eof

Return the file object end-of-file state.

    Enter:
      none.
    Exit:
      1 = next read will return end of file, or file is not open.
      0 = not at end-of-file.

flock

Lock file object (only if opened output).

    Enter:
      $lock = 0 ==> release lock
              1 ==> shared lock
              2 ==> exclusive lock
      $nonblock = 0 or undef ==> default operation
                      1 ==> non-blocking.
    Exit:
      1 if successful
      0 if unsuccessful (e.g. system error, timeout, file not present).

load

Load the contents of the file into an array and return the result.

    Enter:
      none.
    Exit:
      @bufferList = array containing complete file.
      undef if error

    Note:
      Assumes file type is 0.

open

Open file.

    Enter:
      $filename = name of file to open
      $mode = open mode (<, >, >>)
      $type = file type (0 = text, 1 = binary)
    Exit:
      1 if successful
      undef if not successful

read

Return the number of bytes requested from the current file.

($buffer, $size) = $fileio->read($size);

    Enter:
      $size = number of bytes to read.
      $offset = optional buffer offset to beginning write operation.
    Exit:
      $buffer = data read.
      $size   = number of bytes read.
      undef if error or end-of-file.

readln

Return the next line in the file after removing line-end characters.

    Enter:
      none.
    Exit:
      $buffer = next line in file
      undef if error or end-of-file.

seek

Reposition file to specified position.

    Enter:
      $position = position to seek to.
      $type = 0 to seek to $position,
              1 to seek to current position + $position,
              2 to seek to end-of-file + $position
    Exit:
      1 if successful
      0 if error

stat

Return a hash containing the fields returned by the 'stat' command on the file object.

    Enter:
      none.
    Exit:
      %fStat = hash containing fields returned from 'stat'.
      undef if file not found.

tell

Return the current seek pointer for the file.

    Enter:
      none.
    Exit:
      $position if successful
      0 if error

truncate

Truncate the file to the specified length.

    Enter:
      $length = file length to truncate to.
    Exit:
      1 if successful
      undef if error

write

Write the specified number of bytes to the file.

    Enter:
      $buffer = buffer to write to file
      $size = size of data to write.
      $offset = optional buffer offset to beginning write operation.
    Exit:
      $size if successful
      0 if unable to write buffer

writeln

Write a buffer to the file followed by a new-line sequence if the file type is text.

    Enter:
      $buffer = buffer to write to file
    Exit:
      1 if successful
      undef if unable to write buffer

PUBLIC ATTRIBUTES

debug

Set/get the current debug setting.

    Enter:
      $debug = new debug setting (or undef to return current without changing)
    Exit:
      $debug = current debug setting.

Revision

The Revision method returns the revision number of fileIO.pm:

      $revision = $fileIO->Revision;

    Enter:
      none.
    Exit:
      current revision string.

umask

Set/get file creation mode mask.

    Enter:
      $umask = octal file create mode mask
    Exit:
      $umask = current umask

Version

The Version method returns the version number of fileIO.pm:

      $version = $fileIO->Version;

    Enter:
      none.
    Exit:
      current version string.

PRIVATE METHODS

DESTROY

The class destructor is called when the object leaves scope or is explicitly destroyed.

    Enter:
      none.
    Exit:
      none.

AUTHORS

Jay Wheeler (jaywheeler@geocities.com), EarthWalk Software.

http://www.geocities.com/jaywheeler.geo

COPYRIGHT

EWS::global is copyright © 2002. EarthWalk Software.

This module is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This module is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this script; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA, or from the Free Software Foundation web page at

    http://www.fsf.org/licenses/lgpl.txt