goldentine
asked on
Compress in GZIP
I have this function to Unzip Gzip compressed files. What I need is to be able to compress files in the Gzip format.
Using this function as an example, how could I rewrite it to compress in to a "*.gz" file? Thanks in advance.
/**
* 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.
*/
function gunzipFile(infilePath) {
var zipfile = "";
var outfile = "";
var outputPath = "";
var infile = "";
var gzInStream = createObject('java','java. util.zip.G ZIPInputSt ream');
var outStream = createObject('java','java. io.FileOut putStream' );
var inStream = createObject('java','java. io.FileInp utStream') ;
var buffer = repeatString(" ",1024).getBytes();
var length = 0;
var rv = true;
var e = "";
if (arrayLen(Arguments) gte 2) outputPath = arguments[2];
else outputPath = getDirectoryFromPath(infil ePath);
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,1 024);
if (length neq -1) outStream.write(buffer,0,l ength);
} 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;
}
Using this function as an example, how could I rewrite it to compress in to a "*.gz" file? Thanks in advance.
/**
* 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.
*/
function gunzipFile(infilePath) {
var zipfile = "";
var outfile = "";
var outputPath = "";
var infile = "";
var gzInStream = createObject('java','java.
var outStream = createObject('java','java.
var inStream = createObject('java','java.
var buffer = repeatString(" ",1024).getBytes();
var length = 0;
var rv = true;
var e = "";
if (arrayLen(Arguments) gte 2) outputPath = arguments[2];
else outputPath = getDirectoryFromPath(infil
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,1
if (length neq -1) outStream.write(buffer,0,l
} 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;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER