gunzipFile(infilePath[, outputPath])
Last updated May 03, 2010
Version: 1 | Requires: CF6 | Library: UtilityLib
Description:
This function takes one or two parameters (the FULL absolute path to the file to be unzipped) and optionally a directory to unzip the contained file to. Note that this does not extract files in a tar.gz file (it only removes the gzip compression). It assumes that both the source file and option destination exist and are valid.
Return Values:
Returns a boolean.
Example:
<cfset result = gunzipFile(expandPath("./Ray Bio.doc.gz"), "c:\flextemp")>
<cfoutput>#result#</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
infilePath | Full path to gz file. | Yes |
outputPath | Where to extract the gzfile. Defaults to current directory. | No |
Full UDF Source:
/**
* Unzip a gzipped (.gz) file.
*
* @param infilePath Full path to gz file. (Required)
* @param outputPath Where to extract the gzfile. Defaults to current directory. (Optional)
* @return Returns a boolean.
* @author Vaughan Allan (vallan@abnamromorgans.com.au)
* @version 1, May 3, 2010
*/
function gunzipFile(infilePath) {
var zipfile = "";
var outfile = "";
var outputPath = "";
var infile = "";
var gzInStream = createObject('java','java.util.zip.GZIPInputStream');
var outStream = createObject('java','java.io.FileOutputStream');
var inStream = createObject('java','java.io.FileInputStream');
var buffer = repeatString(" ",1024).getBytes();
var length = 0;
var rv = true;
if (arrayLen(Arguments) gte 2) outputPath = arguments[2];
else outputPath = getDirectoryFromPath(infilePath);
if (right(infilePath,3) neq '.gz') infilePath = infilePath & '.gz';
if(right(outputPath,1) neq "/" and right(outputPath,1) neq "\") outputPath = outputPath & "/";
try {
infile = getFileFromPath(infilePath);
outfile = outputPath & left(infile,len(infile) - 3);
inStream.init(infilePath);
gzInStream.init(inStream);
outStream.init(outfile);
do {
length = gzInStream.read(buffer,0,1024);
if (length neq -1) outStream.write(buffer,0,length);
} while (length neq -1);
outStream.close();
gzInStream.close();
}
catch (any e) {
rv = false;
try {
outStream.close();
} catch (any e) { }
try {
gzInStream.close();
} catch (any e) { }
}
return rv;
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016