diff options
author | Robin Appelman <icewind@owncloud.com> | 2014-08-26 18:46:07 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-02-16 13:52:11 +0100 |
commit | d2255a1d304aa5e537e8aa097add2a51aa0e5d89 (patch) | |
tree | 79801d54149e6c8037e717a1d5d6ac43327eb6db /apps/files_external/3rdparty/icewind/smb/src/NativeStream.php | |
parent | 78febb2ee594bac5d483f7c8534ed5eb33c2c528 (diff) | |
download | nextcloud-server-d2255a1d304aa5e537e8aa097add2a51aa0e5d89.tar.gz nextcloud-server-d2255a1d304aa5e537e8aa097add2a51aa0e5d89.zip |
New SMB storage backend
Diffstat (limited to 'apps/files_external/3rdparty/icewind/smb/src/NativeStream.php')
-rw-r--r-- | apps/files_external/3rdparty/icewind/smb/src/NativeStream.php | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/apps/files_external/3rdparty/icewind/smb/src/NativeStream.php b/apps/files_external/3rdparty/icewind/smb/src/NativeStream.php new file mode 100644 index 00000000000..07bd2f1e797 --- /dev/null +++ b/apps/files_external/3rdparty/icewind/smb/src/NativeStream.php @@ -0,0 +1,114 @@ +<?php +/** + * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com> + * This file is licensed under the Licensed under the MIT license: + * http://opensource.org/licenses/MIT + */ + +namespace Icewind\SMB; + +use Icewind\SMB\Exception\InvalidRequestException; +use Icewind\Streams\File; + +class NativeStream implements File { + /** + * @var resource + */ + public $context; + + /** + * @var \Icewind\SMB\NativeState + */ + private $state; + + /** + * @var resource + */ + private $handle; + + /** + * @var bool + */ + private $eof = false; + + /** + * Wrap a stream from libsmbclient-php into a regular php stream + * + * @param \Icewind\SMB\NativeState $state + * @param resource $smbStream + * @param string $mode + * @return resource + */ + public static function wrap($state, $smbStream, $mode) { + stream_wrapper_register('nativesmb', '\Icewind\SMB\NativeStream'); + $context = stream_context_create(array( + 'nativesmb' => array( + 'state' => $state, + 'handle' => $smbStream + ) + )); + $fh = fopen('nativesmb://', $mode, false, $context); + stream_wrapper_unregister('nativesmb'); + return $fh; + } + + public function stream_close() { + return $this->state->close($this->handle); + } + + public function stream_eof() { + return $this->eof; + } + + public function stream_flush() { + } + + + public function stream_open($path, $mode, $options, &$opened_path) { + $context = stream_context_get_options($this->context); + $this->state = $context['nativesmb']['state']; + $this->handle = $context['nativesmb']['handle']; + return true; + } + + public function stream_read($count) { + $result = $this->state->read($this->handle, $count); + if (strlen($result) < $count) { + $this->eof = true; + } + return $result; + } + + public function stream_seek($offset, $whence = SEEK_SET) { + $this->eof = false; + try { + return $this->state->lseek($this->handle, $offset, $whence) !== false; + } catch (InvalidRequestException $e) { + return false; + } + } + + public function stream_stat() { + return $this->state->fstat($this->handle); + } + + public function stream_tell() { + return $this->state->lseek($this->handle, 0, SEEK_CUR); + } + + public function stream_write($data) { + return $this->state->write($this->handle, $data); + } + + public function stream_truncate($size) { + return $this->state->ftruncate($this->handle, $size); + } + + public function stream_set_option($option, $arg1, $arg2) { + return false; + } + + public function stream_lock($operation) { + return false; + } +} |