private function createFileAt(string $path, File $file)
    {
        if ($file instanceof Directory) {
            $folder = $path.'/'.(string) $file->name();

            if (
                $this->files->contains($folder) &&
                $this->files->get($folder) === $file
            ) {
                return;
            }

            $this->filesystem->mkdir($folder);
            $file
                ->modifications()
                ->foreach(function($event) use ($folder) {
                    if ($this->handledEvents->contains($event)) {
                        return;
                    }

                    switch (true) {
                        case $event instanceof FileWasRemoved:
                            $this
                                ->filesystem
                                ->remove($folder.'/'.$event->file());
                            break;
                        case $event instanceof FileWasAdded:
                            $this->createFileAt($folder, $event->file());
                            break;
                    }

                    $this->handledEvents = $this->handledEvents->add($event);
                });
            $this->files = $this->files->put($folder, $file);

            return;
        }

        $path .= '/'.(string) $file->name();

        if (
            $this->files->contains($path) &&
            $this->files->get($path) === $file
        ) {
            return;
        }

        $stream = $file->content();
        $stream->rewind();
        $handle = fopen($path, 'w');

        while (!$stream->end()) {
            fwrite($handle, (string) $stream->read(8192));
        }

        $this->files = $this->files->put($path, $file);
    }