Exemple #1
0
 function resize($size)
 {
     if (!($this->streamMode & Stream::WRITE)) {
         throw FileException::ENOTWRITABLE();
     }
     return ftruncate($this->handle, $size);
 }
Exemple #2
0
 public function resize($size)
 {
     if (!($this->mode & Stream::WRITE)) {
         throw FileException::ENOTWRITABLE();
     }
     // ftruncate manual page states that the file pointer is not changed,
     // hence this is disabled:
     // $this->pos = min($this->pos, $size);
     if ($size > $this->node->length) {
         $this->buffer->data = str_pad($this->buffer->data, $size, "");
     } elseif ($size < $this->node->length) {
         $new = substr($this->buffer->data, 0, $size);
         if ($new === false) {
             throw new \UnexpectedValueException("Buffer of length {$this->node->length} could not be truncated to size {$size}");
         }
         $this->buffer->data = $new;
     }
     $this->node->length = $size;
     return true;
 }