X-Git-Url: https://git.mxchange.org/?p=core.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Ffile_directories%2Fio%2Fclass_FrameworkFileInputOutputPointer.php;h=b167fee3d363d409865c577e24500c5d2e9534d7;hp=04d8cbc9deddccbdae667f83630558989dd7d7e5;hb=978c24260ea30de3b29d4436d707bdc67a8e9b9e;hpb=3ac79dbc1ecc71a1d704992366a0512d46af7785 diff --git a/inc/classes/main/file_directories/io/class_FrameworkFileInputOutputPointer.php b/inc/classes/main/file_directories/io/class_FrameworkFileInputOutputPointer.php index 04d8cbc9..b167fee3 100644 --- a/inc/classes/main/file_directories/io/class_FrameworkFileInputOutputPointer.php +++ b/inc/classes/main/file_directories/io/class_FrameworkFileInputOutputPointer.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class FrameworkFileInputOutputPointer extends BaseFileIo { +class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputPointer { /** * Protected constructor * @@ -38,15 +38,12 @@ class FrameworkFileInputOutputPointer extends BaseFileIo { * * @param $fileName The file name we shall pass to fopen() * @return void - * @throws FileIsEmptyException If the given file name is NULL or empty + * @throws FileIsEmptyException If the given file name is NULL or empty * @throws FileReadProtectedException If PHP cannot read an existing file * @throws FileWriteProtectedException If PHP cannot write an existing file - * @throws FileIoException If fopen() returns not a file resource + * @throws FileIoException If fopen() returns not a file resource */ public static final function createFrameworkFileInputOutputPointer ($fileName) { - // Secure with realpath() - $fileName = realpath($fileName); - // Some pre-sanity checks... if ((is_null($fileName)) || (empty($fileName))) { // No filename given @@ -60,7 +57,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo { } // Try to open a handler - $filePointer = fopen($fileName, 'r+b'); + $filePointer = fopen($fileName, 'c+b'); if ((is_null($filePointer)) || ($filePointer === FALSE)) { // Something bad happend throw new FileIoException($fileName, self::EXCEPTION_FILE_POINTER_INVALID); @@ -118,7 +115,29 @@ class FrameworkFileInputOutputPointer extends BaseFileIo { } // Write data to the file pointer and return written bytes - return fwrite($this->getPointer(), $dataStream); + return fwrite($this->getPointer(), $dataStream, strlen($dataStream)); + } + + /** + * Rewinds to the beginning of the file + * + * @return void + */ + public function rewind () { + // Rewind the pointer + assert(rewind($this->getPointer()) === 1); + } + + /** + * Seeks to given position + * + * @param $seekPosition Seek position in file + * @param $whence "Seek mode" (see http://de.php.net/fseek) + * @return void + */ + public function seek ($seekPosition, $whence = SEEK_SET) { + // Move the file pointer + assert(fseek($this->getPointer(), $seekPosition, $whence) === 0); } }