Update 'sk1/compressor.c'
This commit is contained in:
parent
4725753562
commit
661a538b39
@ -172,7 +172,13 @@ int RLEcompress(struct Input input, struct Output* output) {
|
|||||||
return output->length;
|
return output->length;
|
||||||
}
|
}
|
||||||
|
|
||||||
void compress(FILE* infile, FILE* outfile) {
|
int compress(const char* input_file_name, const char* output_file_name) {
|
||||||
|
FILE *infile = fopen(input_file_name, "rb");
|
||||||
|
if (infile == NULL) {
|
||||||
|
perror("Error opening input file");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
fseek(infile, 0, SEEK_END);
|
fseek(infile, 0, SEEK_END);
|
||||||
int insize = ftell(infile) + 1;
|
int insize = ftell(infile) + 1;
|
||||||
rewind(infile);
|
rewind(infile);
|
||||||
@ -185,6 +191,15 @@ void compress(FILE* infile, FILE* outfile) {
|
|||||||
assert(!ferror(infile));
|
assert(!ferror(infile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fclose(infile);
|
||||||
|
|
||||||
|
FILE *outfile = fopen(output_file_name, "wb");
|
||||||
|
if (outfile == NULL) {
|
||||||
|
perror("Error opening output file");
|
||||||
|
free(buffer);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
struct Input input = {.buffer = buffer, .size = insize};
|
struct Input input = {.buffer = buffer, .size = insize};
|
||||||
struct Output tempOutput;
|
struct Output tempOutput;
|
||||||
|
|
||||||
@ -202,4 +217,7 @@ void compress(FILE* infile, FILE* outfile) {
|
|||||||
free(buffer);
|
free(buffer);
|
||||||
free(tempOutput.result);
|
free(tempOutput.result);
|
||||||
free(finalOutput.result);
|
free(finalOutput.result);
|
||||||
}
|
|
||||||
|
fclose(outfile);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user