2
0
mirror of https://github.com/vasi/pixz synced 2024-11-16 21:26:04 +00:00

Add block-fraction option

This commit is contained in:
Dave Vasilevsky 2012-12-22 18:59:36 -05:00
parent 04b041656d
commit 948d0b4e5d
3 changed files with 18 additions and 4 deletions

9
pixz.c
View File

@ -59,7 +59,8 @@ int main(int argc, char **argv) {
int ch;
char *optend;
long optint;
while ((ch = getopt(argc, argv, "dxli:o:tvhp:0123456789")) != -1) {
double optdbl;
while ((ch = getopt(argc, argv, "dxli:o:tvhp:0123456789f:")) != -1) {
switch (ch) {
case 'd': op = OP_READ; break;
case 'x': op = OP_EXTRACT; break;
@ -68,6 +69,12 @@ int main(int argc, char **argv) {
case 'o': opath = optarg; break;
case 't': tar = false; break;
case 'h': usage(NULL); break;
case 'f':
optdbl = strtod(optarg, &optend);
if (*optend || optdbl <= 0)
usage("Need a positive floating-point argument to -f");
gBlockFraction = optdbl;
break;
case 'p':
optint = strtol(optarg, &optend, 10);
if (optint < 0 || *optend)

2
pixz.h
View File

@ -52,6 +52,8 @@ uint64_t xle64dec(const uint8_t *d);
void xle64enc(uint8_t *d, uint64_t n);
size_t num_threads(void);
extern double gBlockFraction;
#pragma mark INDEX

11
write.c
View File

@ -16,6 +16,8 @@ struct io_block_t {
#pragma mark GLOBALS
double gBlockFraction = 1.0;
static bool gTar = true;
static size_t gBlockInSize = 0, gBlockOutSize = 0;
@ -70,7 +72,9 @@ void pixz_write(bool tar, uint32_t level) {
.options = &lzma_opts };
gFilters[1] = (lzma_filter){ .id = LZMA_VLI_UNKNOWN, .options = NULL };
gBlockInSize = lzma_opts.dict_size * 1.0;
gBlockInSize = lzma_opts.dict_size * gBlockFraction;
if (gBlockInSize <= 0)
die("Block size must be positive");
gBlockOutSize = lzma_block_buffer_bound(gBlockInSize);
pipeline_create(block_create, block_free, read_thread, encode_thread);
@ -234,8 +238,9 @@ static void block_free(void *data) {
static void *block_create() {
io_block_t *ib = malloc(sizeof(io_block_t));
ib->input = malloc(gBlockInSize);
ib->output = malloc(gBlockOutSize);
if (!(ib->input = malloc(gBlockInSize))
|| !(ib->output = malloc(gBlockOutSize)))
die("Can't allocate blocks");
return ib;
}