LZ4Demo now supports Pipe mode (inspired by Huan Truong mod)
git-svn-id: https://lz4.googlecode.com/svn/trunk@13 650e7d94-2a16-8b24-b05c-7c0b3f6821cd
This commit is contained in:
parent
8860e61b4f
commit
3a6d9640fb
2
lz4.c
2
lz4.c
@ -41,7 +41,7 @@
|
|||||||
// Lowering this value reduce memory usage
|
// Lowering this value reduce memory usage
|
||||||
// It may also improve speed, especially if you reach L1 cache size (32KB for Intel, 64KB for AMD)
|
// It may also improve speed, especially if you reach L1 cache size (32KB for Intel, 64KB for AMD)
|
||||||
// Expanding memory usage typically improves compression ratio
|
// Expanding memory usage typically improves compression ratio
|
||||||
// Memory usage formula : N->2^(N+2) Bytes (examples : 17 -> 512KB ; 12 -> 16KB)
|
// Memory usage formula for 32 bits systems : N->2^(N+2) Bytes (examples : 17 -> 512KB ; 12 -> 16KB)
|
||||||
#define HASH_LOG 12
|
#define HASH_LOG 12
|
||||||
|
|
||||||
|
|
||||||
|
72
main.c
72
main.c
@ -26,8 +26,9 @@
|
|||||||
//****************************
|
//****************************
|
||||||
// Includes
|
// Includes
|
||||||
//****************************
|
//****************************
|
||||||
#include <stdio.h> // printf, fopen, fread
|
#include <stdio.h> // fprintf, fopen, fread
|
||||||
#include <stdlib.h> // malloc
|
#include <stdlib.h> // malloc
|
||||||
|
#include <string.h> // strcmp
|
||||||
#include "lz4.h"
|
#include "lz4.h"
|
||||||
|
|
||||||
|
|
||||||
@ -74,19 +75,21 @@
|
|||||||
//****************************
|
//****************************
|
||||||
int usage()
|
int usage()
|
||||||
{
|
{
|
||||||
printf("Usage :\n");
|
fprintf(stderr, "Usage :\n");
|
||||||
printf(" %s [arg] input output\n",BINARY_NAME);
|
fprintf(stderr, " %s [arg] input output\n",BINARY_NAME);
|
||||||
printf("Arguments :\n");
|
fprintf(stderr, "Arguments :\n");
|
||||||
printf(" -c : force compression (default)\n");
|
fprintf(stderr, " -c : force compression (default)\n");
|
||||||
printf(" -d : force decompression \n");
|
fprintf(stderr, " -d : force decompression \n");
|
||||||
printf(" -h : help (this text)\n");
|
fprintf(stderr, " -h : help (this text)\n");
|
||||||
|
fprintf(stderr, "input : can be 'stdin' (pipe) or a filename\n");
|
||||||
|
fprintf(stderr, "output : can be 'stdout' (pipe) or a filename\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int badusage()
|
int badusage()
|
||||||
{
|
{
|
||||||
printf("Wrong parameters\n");
|
fprintf(stderr, "Wrong parameters\n");
|
||||||
usage();
|
usage();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -98,11 +101,27 @@ int compress_file(char* input_filename, char* output_filename)
|
|||||||
U64 compressedfilesize = ARCHIVE_MAGICNUMBER_SIZE;
|
U64 compressedfilesize = ARCHIVE_MAGICNUMBER_SIZE;
|
||||||
char* in_buff;
|
char* in_buff;
|
||||||
char* out_buff;
|
char* out_buff;
|
||||||
FILE* finput = fopen( input_filename, "rb" );
|
FILE* finput;
|
||||||
FILE* foutput = fopen( output_filename, "wb" );
|
FILE* foutput;
|
||||||
|
char stdinmark[] = "stdin";
|
||||||
|
char stdoutmark[] = "stdout";
|
||||||
|
|
||||||
if ( finput==0 ) { printf("Pb opening %s\n", input_filename); return 2; }
|
if (!strcmp (input_filename, stdinmark)) {
|
||||||
if ( foutput==0) { printf("Pb opening %s\n", output_filename); return 3; }
|
fprintf(stderr, "Using stdin for input\n");
|
||||||
|
finput = stdin;
|
||||||
|
} else {
|
||||||
|
finput = fopen( input_filename, "rb" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp (output_filename, stdoutmark)) {
|
||||||
|
fprintf(stderr, "Using stdout for output\n");
|
||||||
|
foutput = stdout;
|
||||||
|
} else {
|
||||||
|
foutput = fopen( output_filename, "wb" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( finput==0 ) { fprintf(stderr, "Pb opening %s\n", input_filename); return 2; }
|
||||||
|
if ( foutput==0) { fprintf(stderr, "Pb opening %s\n", output_filename); return 3; }
|
||||||
|
|
||||||
// Allocate Memory
|
// Allocate Memory
|
||||||
in_buff = malloc(CHUNKSIZE);
|
in_buff = malloc(CHUNKSIZE);
|
||||||
@ -131,7 +150,7 @@ int compress_file(char* input_filename, char* output_filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
printf("Compressed %llu bytes into %llu bytes ==> %.2f%%\n",
|
fprintf(stderr, "Compressed %llu bytes into %llu bytes ==> %.2f%%\n",
|
||||||
(unsigned long long) filesize, (unsigned long long) compressedfilesize, (double)compressedfilesize/filesize*100);
|
(unsigned long long) filesize, (unsigned long long) compressedfilesize, (double)compressedfilesize/filesize*100);
|
||||||
|
|
||||||
fclose(finput);
|
fclose(finput);
|
||||||
@ -146,14 +165,27 @@ int decode_file(char* input_filename, char* output_filename)
|
|||||||
U64 filesize = 0;
|
U64 filesize = 0;
|
||||||
char* in_buff;
|
char* in_buff;
|
||||||
char* out_buff;
|
char* out_buff;
|
||||||
FILE* finput = fopen( input_filename, "rb" );
|
|
||||||
FILE* foutput = fopen( output_filename, "wb" );
|
|
||||||
size_t uselessRet;
|
size_t uselessRet;
|
||||||
int sinkint;
|
int sinkint;
|
||||||
U32 nextSize;
|
U32 nextSize;
|
||||||
|
FILE* finput;
|
||||||
|
FILE* foutput;
|
||||||
|
char stdinmark[] = "stdin";
|
||||||
|
char stdoutmark[] = "stdout";
|
||||||
|
|
||||||
if (finput==0 ) { printf("Pb opening %s\n", input_filename); return 4; }
|
if (!strcmp (input_filename, stdinmark)) {
|
||||||
if (foutput==0) { printf("Pb opening %s\n", output_filename); return 5; }
|
fprintf(stderr, "Using stdin for input\n");
|
||||||
|
finput = stdin;
|
||||||
|
} else {
|
||||||
|
finput = fopen( input_filename, "rb" );
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp (output_filename, stdoutmark)) {
|
||||||
|
fprintf(stderr, "Using stdout for output\n");
|
||||||
|
foutput = stdout;
|
||||||
|
} else {
|
||||||
|
foutput = fopen( output_filename, "wb" );
|
||||||
|
}
|
||||||
|
|
||||||
// Allocate Memory
|
// Allocate Memory
|
||||||
in_buff = malloc(OUT_CHUNKSIZE);
|
in_buff = malloc(OUT_CHUNKSIZE);
|
||||||
@ -161,7 +193,7 @@ int decode_file(char* input_filename, char* output_filename)
|
|||||||
|
|
||||||
// Check Archive Header
|
// Check Archive Header
|
||||||
uselessRet = fread(out_buff, 1, ARCHIVE_MAGICNUMBER_SIZE, finput);
|
uselessRet = fread(out_buff, 1, ARCHIVE_MAGICNUMBER_SIZE, finput);
|
||||||
if (*(U32*)out_buff != ARCHIVE_MAGICNUMBER) { printf("Wrong file : cannot be decoded\n"); return 6; }
|
if (*(U32*)out_buff != ARCHIVE_MAGICNUMBER) { fprintf(stderr,"Wrong file : cannot be decoded\n"); return 6; }
|
||||||
uselessRet = fread(in_buff, 1, 4, finput);
|
uselessRet = fread(in_buff, 1, 4, finput);
|
||||||
nextSize = *(U32*)in_buff;
|
nextSize = *(U32*)in_buff;
|
||||||
|
|
||||||
@ -190,7 +222,7 @@ int decode_file(char* input_filename, char* output_filename)
|
|||||||
fwrite(out_buff, 1, sinkint, foutput);
|
fwrite(out_buff, 1, sinkint, foutput);
|
||||||
|
|
||||||
// Status
|
// Status
|
||||||
printf("Successfully decoded %llu bytes \n", (unsigned long long)filesize);
|
fprintf(stderr, "Successfully decoded %llu bytes \n", (unsigned long long)filesize);
|
||||||
|
|
||||||
fclose(finput);
|
fclose(finput);
|
||||||
fclose(foutput);
|
fclose(foutput);
|
||||||
@ -208,7 +240,7 @@ int main(int argc, char** argv)
|
|||||||
*output_filename=0;
|
*output_filename=0;
|
||||||
|
|
||||||
// Welcome message
|
// Welcome message
|
||||||
printf(WELCOME_MESSAGE);
|
fprintf(stderr, WELCOME_MESSAGE);
|
||||||
|
|
||||||
if (argc<2) { badusage(); return 1; }
|
if (argc<2) { badusage(); return 1; }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user