Removed asserts as they seem to be to hard and returned status code instead.
[core.git] / inc / classes / main / file_directories / io / class_FrameworkFileInputOutputPointer.php
index 88c565cc20c8305c40ea4d83f98305f624254cdf..198c5b09df6c463f8bcdd9a4ee8f84b1d24f7bad 100644 (file)
@@ -38,10 +38,10 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
         *
         * @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) {
                // Some pre-sanity checks...
@@ -57,7 +57,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
                }
 
                // Try to open a handler
-               $filePointer = fopen($fileName, 'a+b');
+               $filePointer = fopen($fileName, 'c+b');
                if ((is_null($filePointer)) || ($filePointer === FALSE)) {
                        // Something bad happend
                        throw new FileIoException($fileName, self::EXCEPTION_FILE_POINTER_INVALID);
@@ -115,7 +115,29 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
                }
 
                // 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      $status         Status of this operation
+        */
+       public function rewind () {
+               // Rewind the pointer
+               return rewind($this->getPointer());
+       }
+
+       /**
+        * Seeks to given position
+        *
+        * @param       $seekPosition   Seek position in file
+        * @param       $whence                 "Seek mode" (see http://de.php.net/fseek)
+        * @return      $status                 Status of this operation
+        */
+       public function seek ($seekPosition, $whence = SEEK_SET) {
+               // Move the file pointer
+               return fseek($this->getPointer(), $seekPosition, $whence);
        }
 }