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

Don't read index unless necessary

This commit is contained in:
Dave Vasilevsky 2010-10-13 23:36:48 -04:00
parent 9d0c5e314a
commit 2c5c33120a
5 changed files with 14 additions and 12 deletions

View File

@ -140,10 +140,11 @@ lzma_vli find_file_index(void **bdatap) {
return ret;
}
lzma_vli read_file_index(void) {
void *bdata;
lzma_vli offset = find_file_index(&bdata);
if (!bdata)
lzma_vli read_file_index(lzma_vli offset) {
void *bdata = NULL;
if (!offset)
offset = find_file_index(&bdata);
if (!offset)
return 0;
while (true) {

2
list.c
View File

@ -40,7 +40,7 @@ int main(int argc, char **argv) {
(uintmax_t)iter.block.uncompressed_size);
}
if (tar && read_file_index()) {
if (tar && read_file_index(0)) {
printf("\n");
dump_file_index(stdout);
free_file_index();

2
pixz.h
View File

@ -57,7 +57,7 @@ bool is_multi_header(const char *name);
void decode_index(void);
lzma_vli find_file_index(void **bdatap);
lzma_vli read_file_index(void);
lzma_vli read_file_index(lzma_vli offset);
void dump_file_index(FILE *out);
void free_file_index(void);

11
pread.c
View File

@ -6,8 +6,8 @@
#include <getopt.h>
/* TODO
* - Don't read index unless necessary?
* - Check sizes of files vs index
* - Test against "normal" xz, txz files
*/
#define DEBUG 0
@ -94,8 +94,9 @@ int main(int argc, char **argv) {
}
}
// TODO: ONly read index if necessary?
gFileIndexOffset = read_file_index();
decode_index();
if (verify)
gFileIndexOffset = read_file_index(0);
wanted_files(argc - optind, argv + optind);
#if DEBUG
for (wanted_t *w = gWantedFiles; w; w = w->next)
@ -122,8 +123,8 @@ int main(int argc, char **argv) {
die("Error reading archive entry");
}
const char *path = archive_entry_pathname(entry);
if (is_multi_header(path))
continue;
// if (is_multi_header(path))
// continue;
size_t size = archive_entry_size(entry);
if (!w)

2
read.c
View File

@ -16,7 +16,7 @@ int main(int argc, char **argv) {
die("Can't open input file");
char *target = argv[2];
if (!read_file_index())
if (!read_file_index(0))
die("File has no index");
extract_file(target);