/**
  * Append to a file.
  *
  * @param File|string $file File instance or a file path as string to append to.
  * @param string $data The data to append to the file.
  * @param resource $context [optional] See PHPs fopen() function for more details.
  * @param bool $create [optional] True to attempt to create the file if it doens't exist.
  *
  * @return int|null The amount of bytes appended to the file.
  */
 public static function append($file, $data, $context = null, $create = true)
 {
     // Convert the file into a path string, return the $default value if failed
     if (($file = self::asPath($file, false)) === null) {
         return null;
     }
     // Make sure the file is valid. If the file shouldn't be created make sure it exists already.
     if ($create) {
         if (!self::isValid($file)) {
             return null;
         }
     } else {
         if (!self::isFile($file)) {
             return null;
         }
     }
     // Open the file with the file writer
     $writer = new FileWriter($file, FileAccessModeFactory::createAppendMode(false));
     if (!$writer->open(null, $context)) {
         return null;
     }
     // Append to the file, return the result
     return $writer->write($data);
 }