summaryrefslogtreecommitdiffstats
path: root/Source/CPack/cmCPackTGZGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/CPack/cmCPackTGZGenerator.cxx')
-rw-r--r--Source/CPack/cmCPackTGZGenerator.cxx136
1 files changed, 79 insertions, 57 deletions
diff --git a/Source/CPack/cmCPackTGZGenerator.cxx b/Source/CPack/cmCPackTGZGenerator.cxx
index 1daaee9..3784a75 100644
--- a/Source/CPack/cmCPackTGZGenerator.cxx
+++ b/Source/CPack/cmCPackTGZGenerator.cxx
@@ -45,6 +45,7 @@ class cmCPackTGZGeneratorForward
//----------------------------------------------------------------------
cmCPackTGZGenerator::cmCPackTGZGenerator()
{
+ this->Compress = true;
}
//----------------------------------------------------------------------
@@ -58,15 +59,17 @@ static const size_t cmCPackTGZ_Data_BlockSize = 16384;
class cmCPackTGZ_Data
{
public:
- cmCPackTGZ_Data(cmCPackTGZGenerator* gen) :
+ cmCPackTGZ_Data(cmCPackTGZGenerator* gen, bool compress) :
OutputStream(0), Generator(gen),
- CompressionLevel(Z_DEFAULT_COMPRESSION) {}
+ CompressionLevel(Z_DEFAULT_COMPRESSION),
+ Compress(compress) {}
std::ostream* OutputStream;
cmCPackTGZGenerator* Generator;
char CompressedBuffer[cmCPackTGZ_Data_BlockSize];
int CompressionLevel;
z_stream ZLibStream;
uLong CRC;
+ bool Compress;
};
//----------------------------------------------------------------------
@@ -84,14 +87,17 @@ int cmCPackTGZ_Data_Open(void *client_data, const char* pathname,
{
cmCPackTGZ_Data *mydata = (cmCPackTGZ_Data*)client_data;
- mydata->ZLibStream.zalloc = Z_NULL;
- mydata->ZLibStream.zfree = Z_NULL;
- mydata->ZLibStream.opaque = Z_NULL;
- int strategy = Z_DEFAULT_STRATEGY;
- if ( deflateInit2(&mydata->ZLibStream, mydata->CompressionLevel,
- Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy) != Z_OK )
+ if ( mydata->Compress )
{
- return -1;
+ mydata->ZLibStream.zalloc = Z_NULL;
+ mydata->ZLibStream.zfree = Z_NULL;
+ mydata->ZLibStream.opaque = Z_NULL;
+ int strategy = Z_DEFAULT_STRATEGY;
+ if ( deflateInit2(&mydata->ZLibStream, mydata->CompressionLevel,
+ Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy) != Z_OK )
+ {
+ return -1;
+ }
}
cmGeneratedFileStream* gf = new cmGeneratedFileStream;
@@ -108,7 +114,10 @@ int cmCPackTGZ_Data_Open(void *client_data, const char* pathname,
return -1;
}
- mydata->CRC = crc32(0L, Z_NULL, 0);
+ if ( mydata->Compress )
+ {
+ mydata->CRC = crc32(0L, Z_NULL, 0);
+ }
return 0;
}
@@ -118,35 +127,42 @@ ssize_t cmCPackTGZ_Data_Write(void *client_data, void *buff, size_t n)
{
cmCPackTGZ_Data *mydata = (cmCPackTGZ_Data*)client_data;
- mydata->ZLibStream.avail_in = n;
- mydata->ZLibStream.next_in = reinterpret_cast<Bytef*>(buff);
-
- do {
- mydata->ZLibStream.avail_out = cmCPackTGZ_Data_BlockSize;
- mydata->ZLibStream.next_out
- = reinterpret_cast<Bytef*>(mydata->CompressedBuffer);
- // no bad return value
- int ret = deflate(&mydata->ZLibStream, (n?Z_NO_FLUSH:Z_FINISH));
- if(ret == Z_STREAM_ERROR)
+ if ( mydata->Compress )
+ {
+ mydata->ZLibStream.avail_in = n;
+ mydata->ZLibStream.next_in = reinterpret_cast<Bytef*>(buff);
+
+ do {
+ mydata->ZLibStream.avail_out = cmCPackTGZ_Data_BlockSize;
+ mydata->ZLibStream.next_out
+ = reinterpret_cast<Bytef*>(mydata->CompressedBuffer);
+ // no bad return value
+ int ret = deflate(&mydata->ZLibStream, (n?Z_NO_FLUSH:Z_FINISH));
+ if(ret == Z_STREAM_ERROR)
+ {
+ return 0;
+ }
+
+ size_t compressedSize
+ = cmCPackTGZ_Data_BlockSize - mydata->ZLibStream.avail_out;
+
+ mydata->OutputStream->write(
+ reinterpret_cast<const char*>(mydata->CompressedBuffer),
+ compressedSize);
+ } while ( mydata->ZLibStream.avail_out == 0 );
+
+ if ( !*mydata->OutputStream )
{
return 0;
}
-
- size_t compressedSize
- = cmCPackTGZ_Data_BlockSize - mydata->ZLibStream.avail_out;
-
- mydata->OutputStream->write(
- reinterpret_cast<const char*>(mydata->CompressedBuffer),
- compressedSize);
- } while ( mydata->ZLibStream.avail_out == 0 );
-
- if ( !*mydata->OutputStream )
- {
- return 0;
+ if ( n )
+ {
+ mydata->CRC = crc32(mydata->CRC, reinterpret_cast<Bytef *>(buff), n);
+ }
}
- if ( n )
+ else
{
- mydata->CRC = crc32(mydata->CRC, reinterpret_cast<Bytef *>(buff), n);
+ mydata->OutputStream->write(buff, n);
}
return n;
}
@@ -156,23 +172,26 @@ int cmCPackTGZ_Data_Close(void *client_data)
{
cmCPackTGZ_Data *mydata = (cmCPackTGZ_Data*)client_data;
- cmCPackTGZ_Data_Write(client_data, 0, 0);
-
- char buffer[8];
- int n;
- uLong x = mydata->CRC;
- for (n = 0; n < 4; n++) {
- buffer[n] = (int)(x & 0xff);
- x >>= 8;
- }
- x = mydata->ZLibStream.total_in;
- for (n = 0; n < 4; n++) {
- buffer[n+4] = (int)(x & 0xff);
- x >>= 8;
- }
-
- mydata->OutputStream->write(buffer, 8);
- (void)deflateEnd(&mydata->ZLibStream);
+ if ( mydata->Compress )
+ {
+ cmCPackTGZ_Data_Write(client_data, 0, 0);
+
+ char buffer[8];
+ int n;
+ uLong x = mydata->CRC;
+ for (n = 0; n < 4; n++) {
+ buffer[n] = (int)(x & 0xff);
+ x >>= 8;
+ }
+ x = mydata->ZLibStream.total_in;
+ for (n = 0; n < 4; n++) {
+ buffer[n+4] = (int)(x & 0xff);
+ x >>= 8;
+ }
+
+ mydata->OutputStream->write(buffer, 8);
+ (void)deflateEnd(&mydata->ZLibStream);
+ }
delete mydata->OutputStream;
mydata->OutputStream = 0;
return (0);
@@ -190,7 +209,7 @@ int cmCPackTGZGenerator::CompressFiles(const char* outFileName,
const char* toplevel, const std::vector<std::string>& files)
{
cmCPackLogger(cmCPackLog::LOG_DEBUG, "Toplevel: " << toplevel << std::endl);
- cmCPackTGZ_Data mydata(this);
+ cmCPackTGZ_Data mydata(this, this->Compress);
TAR *t;
char buf[TAR_MAXPATHLEN];
char pathname[TAR_MAXPATHLEN];
@@ -257,10 +276,13 @@ int cmCPackTGZGenerator::CompressFiles(const char* outFileName,
//----------------------------------------------------------------------
int cmCPackTGZGenerator::GenerateHeader(std::ostream* os)
{
- const int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
- char header[11];
- sprintf(header, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
- Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
- os->write(header, 10);
+ if ( this->Compress )
+ {
+ const int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
+ char header[11];
+ sprintf(header, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
+ Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
+ os->write(header, 10);
+ }
return 1;
}