You are here

public function StringBasedFileContent::truncate in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/mikey179/vfsStream/src/main/php/org/bovigo/vfs/content/StringBasedFileContent.php \org\bovigo\vfs\content\StringBasedFileContent::truncate()

Truncates a file to a given length

Parameters

int $size length to truncate file to:

Return value

bool

Overrides FileContent::truncate

File

vendor/mikey179/vfsStream/src/main/php/org/bovigo/vfs/content/StringBasedFileContent.php, line 86

Class

StringBasedFileContent
Default implementation for file contents based on simple strings.

Namespace

org\bovigo\vfs\content

Code

public function truncate($size) {
  if ($size > $this
    ->size()) {

    // Pad with null-chars if we're "truncating up"
    $this->content .= str_repeat("\0", $size - $this
      ->size());
  }
  else {
    $this->content = substr($this->content, 0, $size);
  }
  return true;
}