void zip::decompress(buffer& compressed, buffer& uncompressed) { fstream out(COMPRESSED, ios::out|ios::trunc); if ( !out ) throw(streamException(out.rdstate())); if ( out.write(compressed.get_base(), compressed.content_sz()) == 0 ) throw(streamException(out.rdstate())); out.close(); system(form("gzip -cd %s > %s", COMPRESSED, UNCOMPRESSED)); fstream in(UNCOMPRESSED, ios::in); if ( !in ) throw(streamException(in.rdstate())); int x = bytes(in); uncompressed.expand_chunk(x); if ( in.read(uncompressed.get_base(), x) == 0 || x != in.gcount() ) throw(streamException(in.rdstate())); uncompressed.set_content_sz(x); in.close(); return; }
void zip::compress(const buffer& uncompressed, buffer& compressed) { //////////////////////////////////////// // code for testing. I know it is slow. //////////////////////////////////////// fstream out(UNCOMPRESSED, ios::out|ios::trunc); if ( !out ) throw(streamException(out.rdstate())); if ( out.write(uncompressed.get_base(), uncompressed.content_sz()) == 0 ) throw(streamException(out.rdstate())); out.close(); system(form("gzip -c %s > %s", UNCOMPRESSED, COMPRESSED)); fstream in(COMPRESSED, ios::in); if ( !in ) throw(streamException(in.rdstate())); int x = bytes(in); compressed.expand_chunk(x); if ( in.read(compressed.get_base(), x) == 0 || x != in.gcount() ) throw(streamException(in.rdstate())); compressed.set_content_sz(x); in.close(); return; }
Boolean info_lib::define_info_base( char* base_name, char* base_desc, char* spec_file_path ) { //MESSAGE(cerr, "define_info_base()"); //debug(cerr, base_name); //debug(cerr, base_desc); //debug(cerr, spec_file_path); char new_db_path[PATHSIZ]; char f_name[PATHSIZ]; char base_uid[UIDSIZ]; strcpy(new_db_path, form("%s/%s", info_lib_path, base_name)); strcpy(base_uid, unique_id()); g_mode_8_3 = 1; info_base* base = get_info_base(base_name) ; /* no checking here. DDK assures unique base name case if ( base == 0 ) { */ ////////////////////////// // check info base path ////////////////////////// if ( check_and_create_dir(new_db_path) == false ) { throw(stringException(form("bad base bath %s", new_db_path))); } ////////////////////////// // remove any old files ////////////////////////// strcpy(f_name, form("%s.%s", base_name, DATA_FILE_SUFFIX)); if ( exist_file(f_name, new_db_path) == true ) del_file(f_name, new_db_path); strcpy(f_name, form("%s.%s", base_name, INDEX_FILE_SUFFIX)); if ( exist_file(f_name, new_db_path) == true ) del_file(f_name, new_db_path); strcpy(f_name, form("%s.%s", base_name, SCHEMA_FILE_SUFFIX)); if ( exist_file(f_name, new_db_path) == true ) del_file(f_name, new_db_path); f_obj_dict -> init_a_base(spec_file_path, new_db_path, base_name); const char* lang; if ((lang = getenv("LC_ALL")) == NULL) if ((lang = getenv("LC_CTYPE")) == NULL) if ((lang = getenv("LANG")) == NULL) lang = "C"; #ifdef DtinfoClient _DtXlateDb db = NULL; char* std_locale = NULL; if (_DtLcxOpenAllDbs(&db) == 0) { char platform[_DtPLATFORM_MAX_LEN + 1]; int execver, compver; if (_DtXlateGetXlateEnv(db, platform, &execver, &compver) == 0) { _DtLcxXlateOpToStd(db, platform, compver, DtLCX_OPER_SETLOCALE, lang, &std_locale, NULL, NULL, NULL); } _DtLcxCloseDb(&db); db = NULL; } #endif base = new info_base(*f_obj_dict, set_nm_list, list_nm_list, new_db_path, base_name, base_desc, base_uid, #ifdef DtinfoClient std_locale ? std_locale : lang, #else lang, #endif mm_version(MAJOR, MINOR) ); info_base_list.insert_as_tail(new dlist_void_ptr_cell(base)); /*************************************/ // add the base name and description // to the names file /*************************************/ char* lib_nm = form("%s/%s", info_lib_path, MAP_FILE_8_3); fstream nm_out(lib_nm, ios::app, open_file_prot()); if ( !nm_out ) { MESSAGE(cerr, form("can't open %s/%s for append", info_lib_path, MAP_FILE_8_3) ); throw(streamException(nm_out.rdstate())); } if ( bytes(nm_out) == 0 ) { char* lib_entry = form("%s\t%s\n", info_lib_name, unique_id()); if ( !(nm_out << lib_entry) ) { MESSAGE(cerr, form("write %s.%s failed", info_lib_path, MAP_FILE_8_3)); throw(streamException(nm_out.rdstate())); } } char* base_entry = form("%s\t%s\t%s\t%s\t%d\t%d\n", base_name, base_desc, base_uid, #ifdef DtinfoClient std_locale ? std_locale: lang, #else lang, #endif MAJOR, MINOR ); #ifdef DtinfoClient if (std_locale) free(std_locale); #endif if ( !(nm_out << base_entry) ) { MESSAGE(cerr, form("write %s.%s failed", info_lib_path, MAP_FILE_8_3)); throw(streamException(nm_out.rdstate())); } nm_out.close(); if ( nm_out.fail() ) { MESSAGE(cerr, form("close %s.%s failed", info_lib_path, MAP_FILE_8_3)); throw(streamException(nm_out.rdstate())); } //} //MESSAGE(cerr, "define() done"); return true; }