2

On a daily basis I am download a GZ file that I will then need to decompress and import the contents into my database table.

I found CFX_Gzip.dll from Adobe Coldfusion Exchange. Anyone know where i put the DLL file? It might go in the CF8/lib/ folder, but i'm not sure.

I'm using Coldfusion8. If there is another gzip decompressor that i should use, i'd be delighted if there is one that is more recent. This one is old and the website from the person that wrote it is gone now. No documentation with it.

3 Answers 3

6

No need of a dll with CF8, use existing java library. Have a look at CFLib or try the following code:

<cfscript>
try{
    /* Set inoutput */
    gzFileName = "myFile.gz";
    outputFile = "mygzFiles";

    /* Initialize gzip */
    var outStream = CreateObject("java","java.io.FileOutputStream");
    var inStream = CreateObject("java","java.io.FileInputStream");
    var inGzipStream = CreateObject("java","java.util.zip.GZIPInputStream");

    outStream.init(outputFile);
    inStream.init(arguments.gzipFilePath);

    inGzipStream.init(instance.ioInput);

    while(l GTE 0){
        outStream.write(buffer, 0, l);
        l = inGzipStream.read(buffer);
    }

    /* Close the GZip file */
    inGzipStream.close();
    inStream.close();
    outStream.ioOutput.close();

} catch(Any){}
</cfscript>
3
  • It is best not swallow errors though. On error, the streams should be closed (to ensure nothing is left in a locked state) and the error reported.
    – Leigh
    Mar 31, 2011 at 19:59
  • Yep, you're right. Seems that we were all "in-sync" to answer that question :-) Apr 1, 2011 at 7:46
  • Yep. With everyone suggesting the same thing, probably means it is the right answer ;)
    – Leigh
    Apr 1, 2011 at 15:44
1

You can use a bit of java to process gzip files http://www.cflib.org/udf/gzip

2
  • @Sergii - How is that possible? ;)
    – Leigh
    Mar 31, 2011 at 19:56
  • @Sergii - Haha. You are doing well then. My brain enters shutdown mode much earlier ;)
    – Leigh
    Mar 31, 2011 at 20:40
1

Possibly not the most elegant solution, but seems to work for my simple test cases:

<cfscript>

    inputFile = "/tmp/test.txt.gz";
    outputFile = "/tmp/test.txt";

    ioInput = CreateObject("java","java.io.FileInputStream");
    gzInput = CreateObject("java","java.util.zip.GZIPInputStream");
    ioOutput = CreateObject("java","java.io.FileOutputStream");

    ioInput.init(inputFile);
    gzInput.init(ioInput);
    ioOutput.init(outputFile);

    line = 0;
    buffer = RepeatString(" ", 1024).getBytes();

    while (line GTE 0) {
        ioOutput.write(buffer, 0, line);
        line = gzInput.read(buffer);
    }

    gzInput.close();
    ioInput.close();
    ioOutput.close();

</cfscript>
1
  • thank you for the replies. I ended up using a CFX called CFX_GZIP.
    – Robbiegod
    Apr 5, 2011 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.