int main(int argc, char* argv[]) { if (argc < 3) { printInfo(); return 0; } char* flag = argv[1]; if (strcmp(flag, "-c") == 0) { int fileSize; //get the buffer from the input file const char* inBuffer = getBufferFromFile(argv[2], fileSize); //make the compressor HuffmanCompressor compressor = HuffmanCompressor((char*)inBuffer, fileSize); long compSize; //compress the data unsigned char* compressedData = compressor.compress(compSize); std::string path = std::string(argv[2]) + ".bzip"; //write the compressed data to the disk writeBinary(compressedData, compSize, path); delete [] compressedData; delete [] inBuffer; return 0; } else if (strcmp(flag, "-d") == 0) { std::fstream in(argv[2], std::ios::in|std::ios::binary); HuffmanDecompressor dec = HuffmanDecompressor(in); BYTE* data = dec.decompress(); int dataSize = dec.getTotalChars(); writeBinary(data, dataSize, "out.txt"); delete [] data; return 0; } else { printInfo(); } return 0; }
void compressFile(string inputFileName, int letterSizeBits, bool debugMode, string password) { HuffmanCompressor* compressor = new HuffmanCompressor(inputFileName, letterSizeBits, debugMode, password); compressor->compress(); }