ParagonIE\Halite\Stream\ReadOnlyFile::reset PHP Method

reset() public method

Set the current cursor position to the desired location
public reset ( integer $position ) : boolean
$position integer
return boolean
    public function reset(int $position = 0) : bool
    {
        $this->pos = $position;
        if (\fseek($this->fp, $position, SEEK_SET) === 0) {
            return true;
        }
        throw new CryptoException\CannotPerformOperation('fseek() failed');
    }

Usage Example

Example #1
0
 public function testFileRead()
 {
     $filename = \tempnam('/tmp', 'x');
     $buf = \Sodium\randombytes_buf(65537);
     \file_put_contents($filename, $buf);
     $fStream = new ReadOnlyFile($filename);
     $this->assertSame($fStream->readBytes(65537), $buf);
     $fStream->reset(0);
     \file_put_contents($filename, Util::safeSubstr($buf, 0, 32768) . 'x' . Util::safeSubstr($buf, 32768));
     try {
         $fStream->readBytes(65537);
         throw new \Exception('fail');
     } catch (CryptoException\FileModified $ex) {
         $this->assertTrue($ex instanceof CryptoException\FileModified);
     }
 }
All Usage Examples Of ParagonIE\Halite\Stream\ReadOnlyFile::reset