Continued:
authorRoland Häder <roland@mxchange.org>
Mon, 7 Dec 2020 11:01:32 +0000 (12:01 +0100)
committerRoland Häder <roland@mxchange.org>
Mon, 7 Dec 2020 11:01:32 +0000 (12:01 +0100)
- seeking to position zero within a zero-sized file doesn't make sense

Signed-off-by: Roland Häder <roland@mxchange.org>
framework/main/classes/file_directories/io/class_FrameworkFileInputOutputPointer.php

index 0f58453cbe23a376aa846fdb956eafc5fbd69ae7..4e79954fad93332afea415cd7348f92db2a45bfa 100644 (file)
@@ -139,7 +139,7 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
         */
        public function writeAtPosition (int $seekPosition, string $dataStream) {
                // Validate parameter
-               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: seekPosition=%d,dataStream()=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream));
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-INPUT-OUTPUT-POINTER: seekPosition=%d,dataStream(%d)=%s - CALLED!', $seekPosition, strlen($dataStream), $dataStream));
                if ($seekPosition < 0) {
                        // Invalid seek position
                        throw new InvalidArgumentException(sprintf('seekPosition=%d is not valid.', $seekPosition));
@@ -148,8 +148,8 @@ class FrameworkFileInputOutputPointer extends BaseFileIo implements InputOutputP
                        throw new InvalidArgumentException('Parameter "dataStream" is empty');
                }
 
-               // First seek to it
-               if (!$this->seek($seekPosition)) {
+               // First seek to it, if file size is larger than zero
+               if ($this->getFileSize() > 0 && !$this->seek($seekPosition)) {
                        // Could not seek
                        throw new InvalidArgumentException(sprintf('Could not seek to seekPosition=%d', $seekPosition));
                }