public static function write(string $path, $data, bool $append = false, bool $lock = false) : int
    {
        $flags = 0;

        if ($append) {
            $flags |= FILE_APPEND;
        }
        if ($lock) {
            $flags |= LOCK_EX;
        }

        $exception = null;

        try {
            $result = ErrorCatcher::run(static function() use ($path, $data, $flags) {
                return file_put_contents($path, $data, $flags);
            });

            if ($result !== false) {
                return $result;
            }
        } catch (\ErrorException $e) {
            $exception = $e;
        }

        throw new IoException('Error writing to ' . $path, 0, $exception);
    }