minor native stream cleanup

This commit is contained in:
Robin Appelman 2021-03-10 14:53:17 +01:00
commit 144439d61f
3 changed files with 9 additions and 28 deletions

View file

@ -38,18 +38,8 @@ class NativeReadStream extends NativeStream {
* @param string $url
* @return resource
*/
public static function wrap($state, $smbStream, $mode, $url) {
stream_wrapper_register('nativesmb', NativeReadStream::class);
$context = stream_context_create([
'nativesmb' => [
'state' => $state,
'handle' => $smbStream,
'url' => $url
]
]);
$fh = fopen('nativesmb://', $mode, false, $context);
stream_wrapper_unregister('nativesmb');
return $fh;
public static function wrap(NativeState $state, $smbStream, string $mode, string $url) {
return parent::wrapClass($state, $smbStream, $mode, $url, NativeReadStream::class);
}
public function stream_read($count) {

View file

@ -12,7 +12,7 @@ use Icewind\SMB\Exception\InvalidRequestException;
use Icewind\Streams\File;
use InvalidArgumentException;
class NativeStream implements File {
abstract class NativeStream implements File {
/**
* @var resource
* @psalm-suppress PropertyNotSetInConstructor
@ -48,10 +48,11 @@ class NativeStream implements File {
* @param resource $smbStream
* @param string $mode
* @param string $url
* @param class-string<NativeStream> $class
* @return resource
*/
public static function wrap($state, $smbStream, $mode, $url) {
stream_wrapper_register('nativesmb', NativeStream::class);
protected static function wrapClass(NativeState $state, $smbStream, string $mode, string $url, string $class) {
stream_wrapper_register('nativesmb', $class);
$context = stream_context_create([
'nativesmb' => [
'state' => $state,

View file

@ -38,18 +38,8 @@ class NativeWriteStream extends NativeStream {
* @param string $url
* @return resource
*/
public static function wrap($state, $smbStream, $mode, $url) {
stream_wrapper_register('nativesmb', NativeWriteStream::class);
$context = stream_context_create([
'nativesmb' => [
'state' => $state,
'handle' => $smbStream,
'url' => $url
]
]);
$fh = fopen('nativesmb://', $mode, false, $context);
stream_wrapper_unregister('nativesmb');
return $fh;
public static function wrap(NativeState $state, $smbStream, string $mode, string $url) {
return parent::wrapClass($state, $smbStream, $mode, $url, NativeWriteStream::class);
}
public function stream_seek($offset, $whence = SEEK_SET) {
@ -66,7 +56,7 @@ class NativeWriteStream extends NativeStream {
}
private function flushWrite(): void {
$this->state->write($this->handle, $this->writeBuffer->flush(), $this->url);
parent::stream_write($this->writeBuffer->flush());
}
public function stream_write($data) {