Skip to main content
Inspiring
February 9, 2011
Question

Handling gz-ed tar files in CF?

  • February 9, 2011
  • 1 reply
  • 1780 views

I'm having problems dealing with files that I am receiving that are gzed tar files.  CFZIP does not handle gz files, but I have tried using a function that I found a while back on fusion coder.com that uses java's ability to handle gziped files.  I uses this code to handle the unzipping:

// Open the compressed file
  localStruct.inFilename = "#arguments.inputFilePath#";
  localStruct.file_in = createobject('java','java.io.FileInputStream').init(localStruct.inFilename);
  localStruct.fin_obj = createobject('java','java.util.zip.GZIPInputStream');
  localStruct.fin = localStruct.fin_obj.init(localStruct.file_in);

But my problem is that this gives me the .tar file, and I cannot find any way of pulling the file out of the tar file.

I used to have success doing a CFEXECUTE of the 7z utility, and it seems to automatically ahndle the tar file because all I give it is the .gz file and it sends me back the actual data file that is inside of the tar.  But I'm setting up a new CF server and having problems getting that kludge to work, and am hoping to find a cleaner way of doing all of this.

Any hints are appreciated.  I've been googling this all over but have not found anything that helps me do this from my CF code.  I'm running CF9 btw.

thanks,

-reed

    This topic has been closed for replies.

    1 reply

    Inspiring
    February 10, 2011

    Did you try this: http://www.trustice.com/java/tar/

    --

    Adam

    Inspiring
    February 10, 2011

    Hi Adam - yes, I saw that when I was googling for ideas, but was not able to see how to incorporate it into my CF code.  I'm a CF guy for a real long time, but not too good with the Java side of things.  Both parts of what I need to do (how to get their code in the CF installation, and how to make the actual java calls) are not clear to me.

    thanks,

    -reed

    Inspiring
    February 11, 2011

    I had a quick look and the structure seems very similar to what you are using now. Just pass your .tar file into a TarArchive. Then use extractContents to extract the files into a directory.

    For installation, I downloaded version 2.5. Then copied the jars/tar.jar file into /web-inf/lib/ and restarted.

    // because the forum s/w hates html tags

    // source .tar file

    input = createObject("java", "java.io.FileInputStream").init("c:/pack.tar");

    archive = createObject("java", "com.ice.tar.TarArchive").init(input);

    // extract contents to this directory

    extractToDir = createObject("java", "java.io.File").init("c:/mytar/");

    archive.extractContents(extractToDir);

    archive.closeArchive();

    input.close();

    WriteOutput("Done");