Skip to content

Commit

Permalink
improve TargetCustom docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jcupitt committed Oct 2, 2024
1 parent 69c343e commit 5f8ed10
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
9 changes: 6 additions & 3 deletions src/SourceCustom.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function __construct()

/**
* Attach a read handler.
*
* The interface is similar to fread. The handler is given a number
* of bytes to fetch, and should return a bytes-like object containing up
* to that number of bytes. If there is no more data available, it should
Expand All @@ -32,16 +33,18 @@ public function onRead(callable $callback): void

/**
* Attach a seek handler.
*
* The interface is the same as fseek, so the handler is passed
* parameters for $offset and $whence with the same meanings.
* However, the handler MUST return the new seek position. A simple way
* to do this is to call ftell() and return that result.
* Seek handlers are optional. If you do not set one, your source will be
* treated as unseekable and libvips will do extra caching.
*
* $whence in particular:
* 0 => start
* 1 => current position
* 2 => end
* - 0 => start
* - 1 => current position
* - 2 => end
*/
public function onSeek(callable $callback): void
{
Expand Down
35 changes: 26 additions & 9 deletions src/TargetCustom.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ public function __construct()

/**
* Attach a write handler.
* The interface is exactly as fwrite. The handler is given a bytes-like object to write,
* and should return the number of bytes written.
*
* The interface is similar to fwrite(). The handler is given a
* bytes-like object to write, and should return the number of bytes
* written.
*
* Unlike fwrite, you should return -1 on error.
*
* @throws Exception
*/
public function onWrite(callable $callback): void
Expand All @@ -31,10 +36,12 @@ public function onWrite(callable $callback): void

/**
* Attach a read handler.
* The interface is similar to fread. The handler is given a number
*
* The interface is similar to fread(). The handler is given a number
* of bytes to fetch, and should return a bytes-like object containing up
* to that number of bytes. If there is no more data available, it should
* return null.
*
* Read handlers on VipsTarget are optional. If you do not set one, your
* target will be treated as unreadable and libvips will be unable to
* write some file types (just TIFF, as of the time of writing).
Expand All @@ -48,16 +55,19 @@ public function onRead(callable $callback): void

/**
* Attach a seek handler.
* The interface is the same as fseek, so the handler is passed
*
* The interface is similar to fseek, so the handler is passed
* parameters for $offset and $whence with the same meanings.
* However, the handler MUST return the new seek position. A simple way
* to do this is to call ftell() and return that result.
*
* Seek handlers are optional. If you do not set one, your source will be
* treated as unseekable and libvips will do extra caching.
*
* $whence in particular:
* 0 => start
* 1 => current position
* 2 => end
* - 0 => start
* - 1 => current position
* - 2 => end
*/
public function onSeek(callable $callback): void
{
Expand All @@ -68,9 +78,12 @@ public function onSeek(callable $callback): void

/**
* Attach an end handler.
*
* This optional handler is called at the end of write. It should do any
* cleaning up necessary, and return 0 on success and -1 on error.
* Automatically falls back to onFinish if libvips <8.13
*
* Automatically falls back to onFinish if libvips <8.13.
*
* @throws Exception
*/
public function onEnd(callable $callback): void
Expand All @@ -84,8 +97,12 @@ public function onEnd(callable $callback): void

/**
* Attach a finish handler.
* For libvips 8.13 and later, this method is deprecated in favour of @throws Exception
*
* For libvips 8.13 and later, this method is deprecated in favour of
* onEnd().
*
* @see TargetCustom::onEnd()
* @throws Exception
*/
public function onFinish(callable $callback): void
{
Expand Down

0 comments on commit 5f8ed10

Please sign in to comment.