mirror of
https://codeberg.org/icewind/streams.git
synced 2026-06-04 09:04:07 +02:00
easier access to source metadata
This commit is contained in:
parent
e4e3221e14
commit
6e347e48d4
2 changed files with 29 additions and 3 deletions
|
|
@ -44,7 +44,7 @@ abstract class Wrapper extends WrapperHandler implements File, Directory {
|
|||
|
||||
public function stream_seek($offset, $whence = SEEK_SET) {
|
||||
$result = fseek($this->source, $offset, $whence);
|
||||
return $result == 0 ? true : false;
|
||||
return $result == 0;
|
||||
}
|
||||
|
||||
public function stream_tell() {
|
||||
|
|
@ -94,8 +94,6 @@ abstract class Wrapper extends WrapperHandler implements File, Directory {
|
|||
public function stream_close() {
|
||||
if (is_resource($this->source)) {
|
||||
return fclose($this->source);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -115,4 +113,19 @@ abstract class Wrapper extends WrapperHandler implements File, Directory {
|
|||
public function getSource() {
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves header/metadata from the source stream.
|
||||
*
|
||||
* This is equivalent to calling `stream_get_meta_data` on the source stream except nested stream wrappers are handled transparently
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMetaData(): array {
|
||||
$meta = stream_get_meta_data($this->source);
|
||||
while (isset($meta['wrapper_data']) && $meta['wrapper_data'] instanceof Wrapper) {
|
||||
$meta = $meta['wrapper_data']->getMetaData();
|
||||
}
|
||||
return $meta;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue