-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathVipsSourceResource.php
41 lines (34 loc) · 1 KB
/
VipsSourceResource.php
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
<?php
namespace Jcupitt\Vips;
use Closure;
class VipsSourceResource extends VipsSourceCustom
{
/**
* @var resource
*/
private $resource;
/**
* The resource passed in will become "owned" by this class. On destruction of this class, the resource will be closed.
*
* @param resource $resource
*/
public function __construct($resource)
{
$this->resource = $resource;
parent::__construct();
$this->onRead(static function (int $length) use ($resource): ?string {
return fread($resource, $length) ?: null;
});
if (stream_get_meta_data($resource)['seekable']) {
$this->onSeek(static function (int $offset, int $whence) use ($resource): int {
fseek($resource, $offset, $whence);
return ftell($resource);
});
}
}
public function __destruct()
{
fclose($this->resource);
parent::__destruct(); // TODO: Change the autogenerated stub
}
}