if (cflag == 1) {
/* Inicio un compresor huffman estatico por chunks */
- if ((shuff = shuff_init_static_bychunk(argv[optind+1],volumesize*1024)) == NULL) return 0;
+ if ((shuff = shuff_init_encoder_bychunk(argv[optind+1],volumesize*1024)) == NULL) return 0;
/* Comprimo por chunks */
if ((fp = fopen(argv[optind],"rb")) == NULL) return 1;
shuff_encode_file(shuff);
/* De init shuffman by chunks */
- shuff_deinit_static_bychunk(shuff);
+ shuff_deinit_encoder(shuff);
/* Free mem allocated by main */
free(shuff);
if (dflag == 1) {
/* Descomprimo */
- return shuff_decode_file(argv[optind],argv[optind+1]);
+ /*return shuff_decode_file(argv[optind],argv[optind+1]);*/
}
return 0;
/* Si llegue al tope de freq acumulada, halve em */
if (chunkshuff->sumfreq == 14930352)
chunkshuff->sumfreq = shuff_rescalefreq(chunkshuff->freqtable);
- }
+ }
+
+ /* Dumpeamos el chunk en el temporal homero */
+ fwrite(chunk,chunksize,1,chunkshuff->coderfp);
return 1;
}
char bit;
SHUFFCODE symbolcode;
- /* Abrimos el file */
+ /* Abrimos el source y el destino */
+ if (shuff->coderfp != NULL) fclose(shuff->coderfp); /* close bychunk temp file */
if ((fpsource = fopen(shuff->sourcefile,"r")) == NULL) return 0;
if ((fpdest = vfopen(shuff->targetfile,"w",shuff->volsize)) == NULL) return 0;
void shuff_deinit_encoder(HUFF_STATE *shuff)
{
/* Libero mallocs y cierro archivos */
- free(shuff->freqtable);
- free(shuff->sourcefile);
- free(shuff->targetfile);
+ free(shuff->freqtable);
if (shuff->coderfp != NULL) fclose(shuff->coderfp);
- if (shuff->decoderfp != NULL) vfclose(shuff->decoderfp);
+ if (shuff->preloadfreq == 1) unlink(shuff->sourcefile);
+ free(shuff->sourcefile);
+ free(shuff->targetfile);
/* Destruyo recursivamente el arbol de codigos */
}
unsigned long int bytesleft; /* cuanto falta descomprimir en un bychunk */
} HUFF_STATE;
+
HUFF_STATE *shuff_init_encoder_byfile(char *inputfile, char *outputfile, long volsize);
HUFF_STATE *shuff_init_encoder_bychunk(char *outputfile, long volsize);
HUFF_STATE *shuff_init_decoder(char *inputfile, char *outputfile);
void shuff_deinit_encoder(HUFF_STATE *shuff);
+int shuff_encode_file(HUFF_STATE *shuff);
int shuff_decode_file(HUFF_STATE *shuff);
#endif /* _STATICHUFF_H_ */