3

I have some .tar.gz-Archives and would like to only unpack the Tarball to create a sha256-checksum hash of the .tar-File. (The reason for this is that the archive will be un- and repacked later on, as we are generating patch-files.)

Now this seems like an easy task but I'm stuck. There are either Gradle examples for:

  1. getting the unpacked tarTree (with a Gradle Copy-Task and tarTree(resources.gzip('model.tar.gz')) (from documentation: working with files)
  2. unzipping Files (with zipTree), which does not work with gzipped files

Both approaches do not work, since I need to create a checksum of the .tar-File itself. Unfortunately I can't use commandLine or gunzip as the tasks should run on both Windows and Linux.

The only solution I can imagine of right now is unpacking the tar.gz to a fileTree and repacking it to a tar-file, but I'm not even sure the checksum would be the same.

Is there really no way to do this directly?

adrianus
  • 3,141
  • 1
  • 22
  • 41

1 Answers1

2

Finally I got it to work with help from a colleague.

Using resources.gzip(), which returns a ReadableResource, we can copy the resulting InputStream into a .tar-file with IOUtils.copy:

file("test.tar").withOutputStream { outputFile ->
    IOUtils.copy(resources.gzip(file("test.tgz")).read(), outputFile)
}

We also needed to add Apache commons ("commons-io:commons-io:2.6") as a dependency.

adrianus
  • 3,141
  • 1
  • 22
  • 41