Continued with file-based stacks and file i/o:
[core.git] / inc / classes / main / file_directories / class_BaseFileIo.php
index a18a8529df11a831ffd6b332cb0fe3e2e7cff126..8cc8f60b11cc3f91949c83e996adf41482f291e4 100644 (file)
@@ -122,6 +122,52 @@ class BaseFileIo extends BaseFrameworkSystem {
        public final function getFileName () {
                return $this->fileName;
        }
+
+       /**
+        * "Getter" for seek position
+        *
+        * @return      $seekPosition   Current seek position
+        */
+       public final function getPosition () {
+               return ftell($this->getPointer());
+       }
+
+       /**
+        * Seek to given offset (default) or other possibilities as fseek() gives.
+        *
+        * @param       $offset         Offset to seek to (or used as "base" for other seeks)
+        * @param       $whence         Added to offset (default: only use offset to seek to)
+        * @return      $status         Status of file seek: 0 = success, -1 = failed
+        */
+       public function seek ($offset, $whence = SEEK_SET) {
+               // Seek to position
+               $status = fseek($this->getPointer(), $offset, $whence);
+
+               // Return status
+               return $status;
+       }
+
+       /**
+        * Size of this file
+        *
+        * @return      $size   Size (in bytes) of file
+        */
+       public function size () {
+               // Get current seek position
+               $seekPosition = $this->getPosition();
+
+               // Seek to end
+               $this->seek(0, SEEK_END);
+
+               // Get position again  (which is the end of the file)
+               $size = $this->getPosition();
+
+               // Reset seek position to old
+               $this->seek($seekPosition);
+
+               // Return size
+               return $size;
+       }
 }
 
 // [EOF]