protected function doDump(array $assets, $directory) {
    $dumped_files = [];

    foreach ($assets as $asset) {

      $content = $asset->getContent();
      $path = $asset->getPath();

      $file_path = "$directory/$path";
      if ($this->filesystem->exists($file_path) && !$asset->isDirectory()) {
        $action = $asset->getAction();
        if ($action == 'replace') {
          $question_text = sprintf('<info>The file <comment>%s</comment> already exists. Would you like to replace it?</info> [<comment>Yes</comment>]:', $file_path);
          if (!$this->confirm($question_text)) {
            continue;
          }
        }
        else {
          $original_content = file_get_contents($file_path);
          if ($action == 'append') {
            $header_size = $asset->getHeaderSize();
            // Do not remove header if original file is empty.
            if ($original_content && $header_size > 0) {
              $content = Utils::removeHeader($content, $header_size);
            }
            $content = $original_content . "\n" . $content;
          }
          elseif (is_callable($action)) {
            $content = $action($original_content, $content);
          }
          else {
            throw new \LogicException("Unsupported action: $action.");
          }
        }
      }

      // Default mode for all parent directories is 0777. It can be modified by
      // changing umask.
      $mode = $asset->getMode();

      // Save data to file system.
      if ($asset->isDirectory()) {
        $this->filesystem->mkdir([$file_path], $mode);
      }
      else {
        $this->filesystem->dumpFile($file_path, $content);
        $this->filesystem->chmod($file_path, $mode);
      }

      $dumped_files[] = $asset->getPath();
    }

    return $dumped_files;
  }