#include <stdio.h>
#include <unistd.h>
-long get_file_size(const char* filename);
+long fsize(const char* filename);
typedef struct _flags_ {
int cflag;
int mflag;
} t_Flags;
-int comprimir(char *src, char *dst, Uint32 pagesize, Uint32 volumensize, t_Flags *flags, char *staticmodel);
+int comprimir(char *src, char *dst, Uint32 pagesize, Uint32 volumesize, t_Flags *flags, char *staticmodel);
int descomprimir(char *src, char *dst);
int main(int argc, char* argv[])
return 0;
}
-long get_file_size(const char* filename)
+long fsize(const char* filename)
{
FILE* file;
long file_size;
total = 0;
while (!feof(fp)) {
i = 0;
- while ((!feof(fp)) && (i < pagesize)) {
- data[i++] = fgetc(fp);
- total++;
- }
+ i = bs_readblock(fp, data, pagesize);
+ total += i;
- /* Saco un EOF que lee de mas */
- if (i<pagesize) i--;
/* Aplico BS guardando su resultado + el K en salida */
bs_solve(data, salida, bs, &k, i);
}
/* Limpiando */
- fclose(fp);
+ if (fclose(fp)) fprintf(stderr, "Error al cerrar archivo de entrada!\n");
bs_destroy(bs);
+ free(data);
+ free(salida);
/* Comprimo con Huffman */
shuff_encode_file(shuff);
free(shuff);
/* Muestro bpb */
- printf("%s: %.04f bit/byte.\n", dst, get_file_size(dst)*8.0f/get_file_size(src));
+ printf("%s: %.04f bits/byte.\n", dst, vfsize(dst)*8.0f/fsize(src));
return 0;
}
free(shuff);
return 0;
}
+