示例#1
0
char *Math::decompress(Compressor::Format format, const char *cbytes, size_t compressedsize, size_t &rawsize)
{
	Compressor *compressor = Compressor::getCompressor(format);

	if (compressor == nullptr)
		throw love::Exception("Invalid compression format.");

	return compressor->decompress(format, cbytes, compressedsize, rawsize);
}
示例#2
0
文件: main.cpp 项目: do-pomian/dfd
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    if (argc < 2)
    {
    	qDebug("insufficient arguments...");
    	usage();
    	exit (0);
    }

    QString option = argv[1];
    Compressor *c = new Compressor ();

    if (option == "--help" || option == "/?")
    {
    	usage();
    	exit(0);
    }
    else if (argc < 4)
    {
    	qDebug() << "insufficient arguments...";
    	usage();
    	exit(0);
    }

    if (option == "-c")
    {
    	c->compress(argv[2], argv[3]);

    }
    else if (option == "-d")
    {
    	c->decompress(argv[2], argv[3]);
    }
    else
    {
    	qDebug("unknown option!");
    	usage();
    	exit (0);
    }

    delete c;

    qDebug("Done!");

    exit (1);
	
    return a.exec();
}
示例#3
0
///
/// readFile: Reads a local file on disk
///
void Parser::readFile(const std::string &fileName){
	
	_fileName = fileName;
	
	//////////////////////////////////////////////////////////////////////////////
	//
	// First find out what kind of file it is using the fileTypeClassifier class:
	//
	//////////////////////////////////////////////////////////////////////////////
	
	//
	// FileTypeClassifier is now a local instance only:
	//
	FileTypeClassifier fileTypeClassifier;
	
	if(!fileTypeClassifier.setFileToTest(_fileName.c_str())){
		Warning("In Parser::readFile(), File %s cannot be located or read and will be ignored",
		        _fileName.c_str() );
		return;
	}
	
	_fileType     = fileTypeClassifier.classify();
	_fileTypeName = fileTypeClassifier.classifyByName();
	
	std::string fileData;
	Compressor newCompressor;
	
	//
	// Message for user:
	//
	std::cout << "Parser::readFile(): Opening a(n) " << _fileTypeName << " file ...\n";
	
	//
	// If the file is compressed, decompress it into a std::string. 
	// Otherwise, read it into a std::string.
	//
	if( _fileType==FileTypeClassifier::PKZIP || 
	    _fileType==FileTypeClassifier::GZIP  || 
	    _fileType==FileTypeClassifier::BZIP2
	)
	{
		//
		// Decompress into a std::string :
		//
		std::cout << "Parser::readFile(): Decompressing " << _fileTypeName << " file ...\n";
		fileData = newCompressor.decompress(_fileName);
	}
	else
	{
		//
		// Read into a std::string :
		//
		fileData = _stringify(_fileName);
	}
	
	////////////////////////////////////////
	//
	// Now process the fileData std::string:
	//
	////////////////////////////////////////
	
	if( _xmlTagManager.discoverFormat(fileData) )
	{
		//
		// fileData are in a recognized XML format:
		//
		std::cout << "Reading file data in " << _xmlTagManager.getFormatName() << " format ...\n";
		_readXML(fileData);
		
	}
	else
	{
		// 
		// If it is not an XML file, then it is a flat file.
		// Two flat file formats are recognized:
		//  
		//  (1) Original Madeline format    (2) Delimited format
		//
		// If there is only 1 block, then it is a tab delimited file. 
		// If there are 2 blocks, it is in Madeline format:
		//
		int blockCount = _determineNumberOfBlocks( fileData );
		if( blockCount == 1)
		{
			
			std::cout << "Reading file data in delimited format ...\n";
			_readDelimited(fileData);
		}
		else if( blockCount == 2)
		{
			
			std::cout << "Reading file data in Madeline flat file format ...\n";
			_readMadeline(fileData);
			
		}
		else
		{
			
			Warning("Parser::readFile(): Sorry, the format of the file %s could not be determined and will be ignored.",
			        _fileName.c_str()
			);
			
		}
	}
}