1Imager::IO(3)         User Contributed Perl Documentation        Imager::IO(3)
2
3
4

NAME

6       Imager::IO - Imager's io_layer object.
7

SYNOPSIS

9         # Imager supplies Imager::IO objects to various callbacks
10         my $IO = ...;
11
12         my $count = $IO->write($data);
13         my $count = $IO->read($buffer, $max_count);
14         my $position = $IO->seek($offset, $whence);
15         my $status = $IO->close;
16

DESCRIPTION

18       Imager uses an abstraction when dealing with image files to allow the
19       same code to work with disk files, in memory data and callbacks.
20
21       If you're writing an Imager file handler your code will be passed an
22       Imager::IO object to write to or read from.
23

METHODS

25       write
26           Call to write to the file.  Returns the number of bytes written.
27           The data provided may contain only characters \x00 to \xFF -
28           characters outside this range will cause this method to croak().
29
30           If you supply a UTF-8 flagged string it will be converted to a byte
31           string, which may have a performance impact.
32
33           Returns -1 on error, though in most cases if the result of the
34           write isn't the number of bytes supplied you'll want to treat it as
35           an error anyway.
36
37       read
38             my $buffer;
39             my $count = $io->read($buffer, $max_bytes);
40
41           Reads up to $max_bytes bytes from the current position in the file
42           and stores them in $buffer.  Returns the number of bytes read on
43           success or an empty list on failure.  Note that a read of zero
44           bytes is not a failure, this indicates end of file.
45
46       read2
47             my $buffer = $io->read2($max_bytes);
48
49           An alternative interface to read, that might be simpler to use in
50           some cases.
51
52           Returns the data read or an empty list.
53
54       seek
55             my $new_position = $io->seek($offset, $whence);
56
57           Seek to a new position in the file.  Possible values for $whence
58           are:
59
60           ·   "SEEK_SET" - $offset is the new position in the file.
61
62           ·   "SEEK_CUR" - $offset is the offset from the current position in
63               the file.
64
65           ·   "SEEK_END" - $offset is the offset relative to the end of the
66               file.
67
68           Note that seeking past the end of the file may or may not result in
69           an error.
70
71           Returns the new position in the file, or -1 on error.
72
73       close
74             my $result = $io->close;
75
76           Call when you're with the file.  If the IO object is connected to a
77           file this won't close the file handle, but buffers may be flushed
78           (if any).
79
80           Returns 0 on success, -1 on failure.
81

AUTHOR

83       Tony Cook <tonyc@cpan.org>
84

SEE ALSO

86       Imager, Imager::Files
87
88
89
90perl v5.12.3                      2011-06-06                     Imager::IO(3)
Impressum