mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 09:14:06 +02:00
minor native stream cleanup
This commit is contained in:
parent
d218982775
commit
144439d61f
3 changed files with 9 additions and 28 deletions
|
|
@ -38,18 +38,8 @@ class NativeReadStream extends NativeStream {
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @return resource
|
* @return resource
|
||||||
*/
|
*/
|
||||||
public static function wrap($state, $smbStream, $mode, $url) {
|
public static function wrap(NativeState $state, $smbStream, string $mode, string $url) {
|
||||||
stream_wrapper_register('nativesmb', NativeReadStream::class);
|
return parent::wrapClass($state, $smbStream, $mode, $url, 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 function stream_read($count) {
|
public function stream_read($count) {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ use Icewind\SMB\Exception\InvalidRequestException;
|
||||||
use Icewind\Streams\File;
|
use Icewind\Streams\File;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class NativeStream implements File {
|
abstract class NativeStream implements File {
|
||||||
/**
|
/**
|
||||||
* @var resource
|
* @var resource
|
||||||
* @psalm-suppress PropertyNotSetInConstructor
|
* @psalm-suppress PropertyNotSetInConstructor
|
||||||
|
|
@ -48,10 +48,11 @@ class NativeStream implements File {
|
||||||
* @param resource $smbStream
|
* @param resource $smbStream
|
||||||
* @param string $mode
|
* @param string $mode
|
||||||
* @param string $url
|
* @param string $url
|
||||||
|
* @param class-string<NativeStream> $class
|
||||||
* @return resource
|
* @return resource
|
||||||
*/
|
*/
|
||||||
public static function wrap($state, $smbStream, $mode, $url) {
|
protected static function wrapClass(NativeState $state, $smbStream, string $mode, string $url, string $class) {
|
||||||
stream_wrapper_register('nativesmb', NativeStream::class);
|
stream_wrapper_register('nativesmb', $class);
|
||||||
$context = stream_context_create([
|
$context = stream_context_create([
|
||||||
'nativesmb' => [
|
'nativesmb' => [
|
||||||
'state' => $state,
|
'state' => $state,
|
||||||
|
|
|
||||||
|
|
@ -38,18 +38,8 @@ class NativeWriteStream extends NativeStream {
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @return resource
|
* @return resource
|
||||||
*/
|
*/
|
||||||
public static function wrap($state, $smbStream, $mode, $url) {
|
public static function wrap(NativeState $state, $smbStream, string $mode, string $url) {
|
||||||
stream_wrapper_register('nativesmb', NativeWriteStream::class);
|
return parent::wrapClass($state, $smbStream, $mode, $url, 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 function stream_seek($offset, $whence = SEEK_SET) {
|
public function stream_seek($offset, $whence = SEEK_SET) {
|
||||||
|
|
@ -66,7 +56,7 @@ class NativeWriteStream extends NativeStream {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function flushWrite(): void {
|
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) {
|
public function stream_write($data) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue