#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;
+ //printf("%s!!!\n", filename);
if (!(file = fopen(filename, "ab"))) return -1;
+ //printf("Abrio!\n");
file_size = ftell(file);
fclose(file);
return 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);
/* Comprimo con Huffman */
free(shuff);
/* Muestro bpb */
- printf("%s: %.04f bits/byte.\n", dst, get_file_size(dst)*8.0f/get_file_size(src));
+ //printf("%s: %ld bytes.\n", src, fsize(src));
+ //printf("%s: %ld bytes.\n", dst, vfsize(dst));
+ printf("%s: %.04f bits/byte.\n", dst, 1.0/fsize(src)*vfsize(dst)*8.0f);
return 0;
}
free(shuff);
return 0;
}
+