コード例 #1
0
void Tree::rebuildOriginalFile(char *pathIn)
{
    string info, aux_s,aux_s2;
    ifstream file;
    unsigned char* buffer;

    info.clear();


    rebuildTree(tree_written);
    //printNo(root);
    equilibrar(tree_written);

    file.open(pathIn, ios::in | ios::binary | ios::ate);

    if(file.is_open()){
        int size = file.tellg();
        file.seekg(0, ios::beg);

        buffer = new unsigned char[size];

        for(int i = 0; i < parada; i++){
            file.get();
        }

        for(int i = parada;i < size-1;i++){
            unsigned char ch = file.get();
            const unsigned char c = (const unsigned char)ch;
            info += charParaString(c);
        }

        aux_s = info;

        const char c = file.get();

        aux_s2 = charParaString(c);
        removeTrash(aux_s2);
        aux_s += aux_s2;
        procurafinal(aux_s);


    }
    else
    {
        cout << "TRASH!" << endl;
    }

    file.close();

}
コード例 #2
0
ファイル: tree.cpp プロジェクト: tenoriomatheus/Huffman
//Reconstrói o arquivo original
void Tree::rebuildOriginalFile(char *pathIn)
{
    std::string info, aux_s,aux_s2;
    std::ifstream file;
    std::string oux, oux2;
    int sobra2 = 0;
    unsigned char* buffer;
    int x = 0;

    info.clear();



    rebuildTree(tree_written);

    //printNo(root);


    equilibrar(tree_written);



    file.open(pathIn, std::ios::in | std::ios::binary | std::ios::ate);


    if(file.is_open())
    {
        int size = file.tellg();
        file.seekg(0, std::ios::beg);

        buffer = new unsigned char[size];

        for(int i = 0; i < parada; i++)
        {
            file.get();
        }



        for(int i = parada;i < size-1;i++)
        {
            unsigned char ch = file.get();
            const unsigned char c = (const unsigned char)ch;



            info += charParaString(c);
            //ajeitar



            /*
        if(info.length() == 1024)
        {
            //sobra2 = info.length() - 1024;
            //oux = info.substr(1024, sobra2);
            //oux2 = info.substr(0,1024);

            aux_s = procura(info,&x);

            cout << "aux_s size: " << aux_s.length() << endl;
            info.clear();

            info += aux_s;
            //info += oux;

            aux_s.clear();
            //oux.clear();
            //oux2.clear();
        }
        */

        }



        //x = info.length();

        int sobra = 1024 - info.length();

        //aux_s = info.substr(x,sobra);
        aux_s = info;



        const char c = file.get();

        aux_s2 = charParaString(c);

        removeTrash(aux_s2);

        aux_s += aux_s2;


        //        cout << "aux_s: ";
        //        for(int i = 0; i < aux_s.length();i++)
        //        {
        //            cout << aux_s[i] << " ";
        //            if((i-1)%8 == 0 && i != 0)
        //            {
        //                cout << endl;
        //                cout << "aux_s: ";
        //            }
        //        }

        procurafinal(aux_s);


    }
    else
    {
        cout << "eRRO!" << endl;
    }

    file.close();

}