1
0
forked from me/IronOS

Move string compression to Python

... so that the script can know its uncompressed size and calculate the
appropriate buffer size.
This commit is contained in:
Alvin Wong
2021-04-16 17:55:30 +08:00
parent 90426b2b22
commit 6f4f4d9733
4 changed files with 111 additions and 68 deletions

View File

@@ -1,48 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "lzfx.h"
/* Program to demonstrate file compression. Don't use it in the real world! */
int main(int argc, char **argv) {
if (argc == 3) {
/* open input */
FILE *f = fopen(argv[1], "rb");
if (!f) {
printf("Error: %s\n", argv[1]);
return 1;
}
/* get size */
fseek(f, 0, SEEK_END);
int inputsize = ftell(f);
fseek(f, 0, SEEK_SET);
/* read */
char *input = malloc(inputsize);
fread(input, inputsize, 1, f);
fclose(f);
/* compress */
int outputsize = inputsize + 1; /* buffer overflow */
char *output = malloc(outputsize);
lzfx_compress(input, inputsize, output, &outputsize);
/* open output */
f = fopen(argv[2], "wb");
if (!f) {
printf("Error: %s\n", argv[1]);
return 1;
}
/* write */
fwrite(output, outputsize, 1, f);
fclose(f);
return 0;
} else {
printf("Compresses a file.\n\nUsage: lzfx-raw input output\n");
return 1;
}
}