#include #include #include #include #include void usage(){ printf("usage : bitcopy \n"); } int main(int argc, char ** argv){ EydLib::BitGroup data; int cell_size; std::string original; std::string copy; if (argc<2){ usage(); exit(-1); } cell_size = atoi(argv[1]); original = argv[2]; copy = original + ".rl1"; EydLib::BitReader bitread(cell_size, 256); bitread.open(original); EydLib::BitWriter bitwrite(cell_size,256); bitwrite.open(copy); unsigned char c = (unsigned char)cell_size; bitwrite.writeDirect(&c, 1); EydLib::BitCompressor compressor; printf("File opened\n"); bool done=false; std::vector record; while(!done){ try{ data = bitread.read(); compressor.append(data); if (compressor.hasContent()){ std::list compressedData = compressor.flush(); std::list::iterator cmpDataIt; for(cmpDataIt = compressedData.begin(); cmpDataIt != compressedData.end(); cmpDataIt++){ bitwrite.write((*cmpDataIt)); // cellule } } } catch (EydLib::eBitReaderEndOfFile& e) { done = true; // TODO: on flushe le contenu de record compressor.flushRleData(); std::list compressedData = compressor.flush(); } catch (std::exception& e){ printf("ERROR\n"); } } printf("compression done\n"); bitread.close(); bitwrite.close(); printf("file closed\n"); }