static Callable<LocalImage> retrieveDockerDaemonLayersStep(
      BuildContext buildContext,
      ProgressEventDispatcher.Factory progressEventDispatcherFactory,
      DockerClient dockerClient,
      TempDirectoryProvider tempDirectoryProvider) {
    return () -> {
      ImageReference imageReference = buildContext.getBaseImageConfiguration().getImage();
      try (ProgressEventDispatcher progressEventDispatcher =
              progressEventDispatcherFactory.create("processing base image " + imageReference, 2);
          TimerEventDispatcher ignored =
              new TimerEventDispatcher(
                  buildContext.getEventHandlers(),
                  "Saving " + imageReference + " from Docker daemon")) {
        ImageDetails dockerImageDetails = dockerClient.inspect(imageReference);
        Optional<LocalImage> cachedImage =
            getCachedDockerImage(buildContext.getBaseImageLayersCache(), dockerImageDetails);
        if (cachedImage.isPresent()) {
          PlatformChecker.checkManifestPlatform(
              buildContext, cachedImage.get().configurationTemplate);
          return cachedImage.get();
        }

        Path tarPath = tempDirectoryProvider.newDirectory().resolve("out.tar");
        long size = dockerImageDetails.getSize();
        try (ProgressEventDispatcher dockerProgress =
                progressEventDispatcher
                    .newChildProducer()
                    .create("saving base image " + imageReference, size);
            ThrottledAccumulatingConsumer throttledProgressReporter =
                new ThrottledAccumulatingConsumer(dockerProgress::dispatchProgress)) {
          dockerClient.save(imageReference, tarPath, throttledProgressReporter);
        }

        LocalImage localImage =
            cacheDockerImageTar(
                buildContext,
                tarPath,
                progressEventDispatcher.newChildProducer(),
                tempDirectoryProvider);
        PlatformChecker.checkManifestPlatform(buildContext, localImage.configurationTemplate);
        return localImage;
      }
    };
  }
Checks the first two bytes of a file to see if it has been gzipped.

@param path the file to check
@return {@code true} if the file is gzipped, {@code false} if not
@throws IOException if reading the file fails
@see <a href="http://www.zlib.org/rfc-gzip.html#file-format">GZIP file format</a>
jib-core/src/main/java/com/google/cloud/tools/jib/builder/steps/LocalBaseImageSteps.java