/usr/lib/perl5/Imager/IO.pod is in libimager-perl 0.98+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | =head1 NAME
Imager::IO - Imager's io_layer object.
=head1 SYNOPSIS
# Imager supplies Imager::IO objects to various callbacks
my $IO = ...;
my $count = $IO->write($data);
my $count = $IO->read($buffer, $max_count);
my $position = $IO->seek($offset, $whence);
my $status = $IO->close;
=head1 DESCRIPTION
Imager uses an abstraction when dealing with image files to allow the
same code to work with disk files, in memory data and callbacks.
If you're writing an Imager file handler your code will be passed an
Imager::IO object to write to or read from.
X<UTF-8>X<Unicode>Note that Imager::IO can only work with collections of bytes -
if you need to read UTF-8 data you will need to read the bytes and
decode them. If you want to write UTF-8 data you will need to encode
your characters to bytes and write the bytes.
=head1 CONSTRUCTORS
=over
=item new_fd($fd)
Create a new I/O layer based on a file descriptor.
my $io = Imager::IO->new(fileno($fh));
=item new_buffer($data)
Create a new I/O layer based on a memory buffer.
The supplied variable must not be changed during the life of the I/O
object.
Buffer I/O layers are read only.
=item new_cb($writecb, $readcb, $seekcb, $closecb)
Create a new I/O layer based on callbacks. See
L<Imager::Files/"I/O Callbacks"> for details on the behavior of
the callbacks.
=item new_fh($fh)
Create a new I/O layer based on a perl file handle.
=item new_bufchain()
Create a new C<bufchain> based I/O layer. This accumulates the file
data as a chain of buffers starting from an empty stream.
Use the L</slurp()> method to retrieve the accumulated content into a
perl string.
=back
=head1 BUFFERED I/O METHODS
These methods use buffered I/O to improve performance unless you call
set_buffered() to disable buffering.
Prior to Imager 0.86 the write and read methods performed raw I/O.
=over
=item write($data)
Call to write to the file. Returns the number of bytes written. The
data provided may contain only characters \x00 to \xFF - characters
outside this range will cause this method to croak().
If you supply a UTF-8 flagged string it will be converted to a byte
string, which may have a performance impact.
Returns -1 on error, though in most cases if the result of the write
isn't the number of bytes supplied you'll want to treat it as an error
anyway.
=item read($buffer, $size)
my $buffer;
my $count = $io->read($buffer, $max_bytes);
Reads up to I<$max_bytes> bytes from the current position in the file
and stores them in I<$buffer>. Returns the number of bytes read on
success or an empty list on failure. Note that a read of zero bytes
is B<not> a failure, this indicates end of file.
=item read2($size)
my $buffer = $io->read2($max_bytes);
An alternative interface to read, that might be simpler to use in some
cases.
Returns the data read or an empty list. At end of file the data read
will be an empty string.
=item seek($offset, $whence)
my $new_position = $io->seek($offset, $whence);
Seek to a new position in the file. Possible values for I<$whence> are:
=over
=item *
C<SEEK_SET> - I<$offset> is the new position in the file.
=item *
C<SEEK_CUR> - I<$offset> is the offset from the current position in
the file.
=item *
C<SEEK_END> - I<$offset> is the offset relative to the end of the
file.
=back
Note that seeking past the end of the file may or may not result in an
error.
Any buffered output will be flushed, if flushing fails, seek() will
return -1.
Returns the new position in the file, or -1 on error.
=item getc()
Return the next byte from the stream.
Returns the ordinal of the byte or -1 on error or end of file.
while ((my $c = $io->getc) != -1) {
print chr($c);
}
=item gets()
=item gets($max_size)
=item gets($max_size, $end_of_line)
Returns the next line of input from the stream, as terminated by
C<end_of_line>.
The default C<max_size> is 8192.
The default C<end_of_line> is C<ord "\n">.
Returns nothing if the stream is in error or at end of file.
Returns the line as a string, including the line terminator (if one
was found) on success.
while (defined(my $line = $io->gets)) {
# do something with $line
}
=item peekc()
Return the buffered next character from the stream, loading the buffer
if necessary.
For an unbuffered stream a buffer will be setup and loaded with a
single character.
Returns the ordinal of the byte or -1 on error or end of file.
my $c = $io->peekc;
=item peekn($size)
Returns up to the next C<size> bytes from the file as a string.
Only up to the stream buffer size bytes (currently 8192) can be peeked.
This method ignores the buffering state of the stream.
Returns nothing on EOF.
my $s = $io->peekn(4);
if ($s =~ /^(II|MM)\*\0/) {
print "TIFF image";
}
=item putc($code)
Write a single character to the stream.
Returns C<code> on success, or -1 on failure.
=item close()
my $result = $io->close;
Call when you're done with the file. If the IO object is connected to
a file this won't close the file handle, but buffers may be flushed
(if any).
Returns 0 on success, -1 on failure.
=item eof()
$io->eof
Test if the stream is at end of file. No further read requests will
be passed to your read callback until you seek().
=item error()
Test if the stream has encountered a read or write error.
my $data = $io->read2(100);
$io->error
and die "Failed";
When the stream has the error flag set no further read or write
requests will be passed to your callbacks until you seek.
=item flush()
$io->flush
or die "Flush error";
Flush any buffered output. This will not call lower write layers when
the stream has it's error flag set.
Returns a true value on success.
=item is_buffered()
Test if buffering is enabled for this stream.
Returns a true value if the stream is buffered.
=item set_buffered($enabled)
If C<$enabled> is a non-zero integer, enable buffering, other disable
it.
Disabling buffering will flush any buffered output, but any buffered
input will be retained and consumed by input methods.
Returns true if any buffered output was flushed successfully, false if
there was an error flushing output.
=back
=head1 RAW I/O METHODS
These call the underlying I/O abstraction directly.
=over
=item raw_write()
Call to write to the file. Returns the number of bytes written. The
data provided may contain only characters \x00 to \xFF - characters
outside this range will cause this method to croak().
If you supply a UTF-8 flagged string it will be converted to a byte
string, which may have a performance impact.
Returns -1 on error, though in most cases if the result of the write
isn't the number of bytes supplied you'll want to treat it as an error
anyway.
=item raw_read()
my $buffer;
my $count = $io->raw_read($buffer, $max_bytes);
Reads up to I<$max_bytes> bytes from the current position in the file
and stores them in I<$buffer>. Returns the number of bytes read on
success or an empty list on failure. Note that a read of zero bytes
is B<not> a failure, this indicates end of file.
=item raw_read2()
my $buffer = $io->raw_read2($max_bytes);
An alternative interface to raw_read, that might be simpler to use in some
cases.
Returns the data read or an empty list.
=item raw_seek()
my $new_position = $io->raw_seek($offset, $whence);
Seek to a new position in the file. Possible values for I<$whence> are:
=over
=item *
C<SEEK_SET> - I<$offset> is the new position in the file.
=item *
C<SEEK_CUR> - I<$offset> is the offset from the current position in
the file.
=item *
C<SEEK_END> - I<$offset> is the offset relative to the end of the
file.
=back
Note that seeking past the end of the file may or may not result in an
error.
Returns the new position in the file, or -1 on error.
=item raw_close()
my $result = $io->raw_close;
Call when you're done with the file. If the IO object is connected to
a file this won't close the file handle.
Returns 0 on success, -1 on failure.
=back
=head1 UTILITY METHODS
=over
=item slurp()
Retrieve the data accumulated from an I/O layer object created with
the new_bufchain() method.
my $data = $io->slurp;
=item dump()
Dump the internal buffering state of the I/O object to C<stderr>.
$io->dump();
=back
=head1 AUTHOR
Tony Cook <tonyc@cpan.org>
=head1 SEE ALSO
Imager, Imager::Files
=cut
|