3 Imager::IO - Imager's io_layer object.
7 # Imager supplies Imager::IO objects to various callbacks
10 my $count = $IO->write($data);
11 my $count = $IO->read($buffer, $max_count);
12 my $position = $IO->seek($offset, $whence);
13 my $status = $IO->close;
17 Imager uses an abstraction when dealing with image files to allow the
18 same code to work with disk files, in memory data and callbacks.
20 If you're writing an Imager file handler your code will be passed an
21 Imager::IO object to write to or read from.
29 Call to write to the file. Returns the number of bytes written. The
30 data provided may contain only characters \x00 to \xFF - characters
31 outside this range will cause this method to croak().
33 If you supply a UTF-8 flagged string it will be converted to a byte
34 string, which may have a performance impact.
36 Returns -1 on error, though in most cases if the result of the write
37 isn't the number of bytes supplied you'll want to treat it as an error
43 my $count = $io->read($buffer, $max_bytes);
45 Reads up to I<$max_bytes> bytes from the current position in the file
46 and stores them in I<$buffer>. Returns the number of bytes read on
47 success or an empty list on failure. Note that a read of zero bytes
48 is B<not> a failure, this indicates end of file.
52 my $buffer = $io->read2($max_bytes);
54 An alternative interface to read, that might be simpler to use in some
57 Returns the data read or an empty list.
61 my $new_position = $io->seek($offset, $whence);
63 Seek to a new position in the file. Possible values for I<$whence> are:
69 C<SEEK_SET> - I<$offset> is the new position in the file.
73 C<SEEK_CUR> - I<$offset> is the offset from the current position in
78 C<SEEK_END> - I<$offset> is the offset relative to the end of the
83 Note that seeking past the end of the file may or may not result in an
86 Returns the new position in the file, or -1 on error.
90 my $result = $io->close;
92 Call when you're with the file. If the IO object is connected to a
93 file this won't close the file handle, but buffers may be flushed (if
96 Returns 0 on success, -1 on failure.
102 Tony Cook <tony@imager.perl.org>
106 Imager, Imager::Files