/**
  * Create the wished file at the given absolute path
  *
  * @param string $path
  * @param FileInterface $file
  *
  * @return void
  */
 private function createFileAt(string $path, FileInterface $file)
 {
     if ($file instanceof DirectoryInterface) {
         $folder = $path . '/' . (string) $file->name();
         if ($this->files->contains($folder) && $this->files->get($folder) === $file) {
             return;
         }
         $this->filesystem->mkdir($folder);
         $file->recordedEvents()->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->isEof()) {
         fwrite($handle, $stream->read(8192));
     }
     $this->files = $this->files->put($path, $file);
 }