diff options
-rw-r--r-- | src/main/TODO | 1 | ||||
-rw-r--r-- | src/main/extractor_datasource.c | 53 |
2 files changed, 46 insertions, 8 deletions
diff --git a/src/main/TODO b/src/main/TODO index 19f7787..b897a54 100644 --- a/src/main/TODO +++ b/src/main/TODO | |||
@@ -1,5 +1,4 @@ | |||
1 | * bz2 decompression (not implemented) | 1 | * bz2 decompression (not implemented) |
2 | * extract-from-gz-file test fails! | ||
3 | * extract-from-bz2-file test fails! | 2 | * extract-from-bz2-file test fails! |
4 | 3 | ||
5 | * MAX_META_DATA buffer of 32 MB is a bit big as a non-growing default size; | 4 | * MAX_META_DATA buffer of 32 MB is a bit big as a non-growing default size; |
diff --git a/src/main/extractor_datasource.c b/src/main/extractor_datasource.c index 0abcb55..d4fd512 100644 --- a/src/main/extractor_datasource.c +++ b/src/main/extractor_datasource.c | |||
@@ -447,6 +447,7 @@ bfds_read (struct BufferedFileDataSource *bfds, | |||
447 | } | 447 | } |
448 | 448 | ||
449 | 449 | ||
450 | #if HAVE_ZLIB | ||
450 | /** | 451 | /** |
451 | * Reset gz-compressed data stream to the beginning. | 452 | * Reset gz-compressed data stream to the beginning. |
452 | * | 453 | * |
@@ -483,8 +484,10 @@ cfs_reset_stream_zlib (struct CompressedFileSource *cfs) | |||
483 | cfs->fpos = 0; | 484 | cfs->fpos = 0; |
484 | return 1; | 485 | return 1; |
485 | } | 486 | } |
487 | #endif | ||
486 | 488 | ||
487 | 489 | ||
490 | #if HAVE_LIBBZ2 | ||
488 | /** | 491 | /** |
489 | * Reset bz2-compressed data stream to the beginning. | 492 | * Reset bz2-compressed data stream to the beginning. |
490 | * | 493 | * |
@@ -494,10 +497,16 @@ cfs_reset_stream_zlib (struct CompressedFileSource *cfs) | |||
494 | static int | 497 | static int |
495 | cfs_reset_stream_bz2 (struct CompressedFileSource *cfs) | 498 | cfs_reset_stream_bz2 (struct CompressedFileSource *cfs) |
496 | { | 499 | { |
497 | /* not implemented */ | 500 | BZ2_bzDecompressEnd (&cfs->bstrm); |
498 | LOG ("bz2 decompression not implemented\n"); | 501 | if (BZ_OK != |
499 | return -1; | 502 | BZ2_bzDecompressInit (&cfs->bstrm, 0, 0)) |
503 | { | ||
504 | LOG ("Failed to reinitialize BZ2 decompressor\n"); | ||
505 | return -1; | ||
506 | } | ||
507 | return 1; | ||
500 | } | 508 | } |
509 | #endif | ||
501 | 510 | ||
502 | 511 | ||
503 | /** | 512 | /** |
@@ -514,10 +523,14 @@ cfs_reset_stream (struct CompressedFileSource *cfs) | |||
514 | { | 523 | { |
515 | switch (cfs->compression_type) | 524 | switch (cfs->compression_type) |
516 | { | 525 | { |
526 | #if HAVE_ZLIB | ||
517 | case COMP_TYPE_ZLIB: | 527 | case COMP_TYPE_ZLIB: |
518 | return cfs_reset_stream_zlib (cfs); | 528 | return cfs_reset_stream_zlib (cfs); |
529 | #endif | ||
530 | #if HAVE_LIBBZ2 | ||
519 | case COMP_TYPE_BZ2: | 531 | case COMP_TYPE_BZ2: |
520 | return cfs_reset_stream_bz2 (cfs); | 532 | return cfs_reset_stream_bz2 (cfs); |
533 | #endif | ||
521 | default: | 534 | default: |
522 | LOG ("invalid compression type selected\n"); | 535 | LOG ("invalid compression type selected\n"); |
523 | return -1; | 536 | return -1; |
@@ -525,6 +538,7 @@ cfs_reset_stream (struct CompressedFileSource *cfs) | |||
525 | } | 538 | } |
526 | 539 | ||
527 | 540 | ||
541 | #if HAVE_ZLIB | ||
528 | /** | 542 | /** |
529 | * Initializes gz-decompression object. Might report metadata about | 543 | * Initializes gz-decompression object. Might report metadata about |
530 | * compresse stream, if available. Resets the stream to the beginning. | 544 | * compresse stream, if available. Resets the stream to the beginning. |
@@ -628,8 +642,10 @@ cfs_init_decompressor_zlib (struct CompressedFileSource *cfs, | |||
628 | cfs->gzip_header_length = gzip_header_length; | 642 | cfs->gzip_header_length = gzip_header_length; |
629 | return cfs_reset_stream_zlib (cfs); | 643 | return cfs_reset_stream_zlib (cfs); |
630 | } | 644 | } |
645 | #endif | ||
631 | 646 | ||
632 | 647 | ||
648 | #if HAVE_LIBBZ2 | ||
633 | /** | 649 | /** |
634 | * Initializes bz2-decompression object. Might report metadata about | 650 | * Initializes bz2-decompression object. Might report metadata about |
635 | * compresse stream, if available. Resets the stream to the beginning. | 651 | * compresse stream, if available. Resets the stream to the beginning. |
@@ -643,9 +659,12 @@ static int | |||
643 | cfs_init_decompressor_bz2 (struct CompressedFileSource *cfs, | 659 | cfs_init_decompressor_bz2 (struct CompressedFileSource *cfs, |
644 | EXTRACTOR_MetaDataProcessor proc, void *proc_cls) | 660 | EXTRACTOR_MetaDataProcessor proc, void *proc_cls) |
645 | { | 661 | { |
646 | LOG ("bz2 decompression not implemented\n"); | 662 | if (BZ_OK != |
647 | return -1; | 663 | BZ2_bzDecompressInit (&cfs->bstrm, 0, 0)) |
664 | return -1; | ||
665 | return 1; | ||
648 | } | 666 | } |
667 | #endif | ||
649 | 668 | ||
650 | 669 | ||
651 | /** | 670 | /** |
@@ -663,10 +682,14 @@ cfs_init_decompressor (struct CompressedFileSource *cfs, | |||
663 | { | 682 | { |
664 | switch (cfs->compression_type) | 683 | switch (cfs->compression_type) |
665 | { | 684 | { |
685 | #if HAVE_ZLIB | ||
666 | case COMP_TYPE_ZLIB: | 686 | case COMP_TYPE_ZLIB: |
667 | return cfs_init_decompressor_zlib (cfs, proc, proc_cls); | 687 | return cfs_init_decompressor_zlib (cfs, proc, proc_cls); |
688 | #endif | ||
689 | #if HAVE_LIBBZ2 | ||
668 | case COMP_TYPE_BZ2: | 690 | case COMP_TYPE_BZ2: |
669 | return cfs_init_decompressor_bz2 (cfs, proc, proc_cls); | 691 | return cfs_init_decompressor_bz2 (cfs, proc, proc_cls); |
692 | #endif | ||
670 | default: | 693 | default: |
671 | LOG ("invalid compression type selected\n"); | 694 | LOG ("invalid compression type selected\n"); |
672 | return -1; | 695 | return -1; |
@@ -674,6 +697,7 @@ cfs_init_decompressor (struct CompressedFileSource *cfs, | |||
674 | } | 697 | } |
675 | 698 | ||
676 | 699 | ||
700 | #if HAVE_ZLIB | ||
677 | /** | 701 | /** |
678 | * Deinitializes gz-decompression object. | 702 | * Deinitializes gz-decompression object. |
679 | * | 703 | * |
@@ -686,8 +710,10 @@ cfs_deinit_decompressor_zlib (struct CompressedFileSource *cfs) | |||
686 | inflateEnd (&cfs->strm); | 710 | inflateEnd (&cfs->strm); |
687 | return 1; | 711 | return 1; |
688 | } | 712 | } |
713 | #endif | ||
689 | 714 | ||
690 | 715 | ||
716 | #if HAVE_LIBBZ2 | ||
691 | /** | 717 | /** |
692 | * Deinitializes bz2-decompression object. | 718 | * Deinitializes bz2-decompression object. |
693 | * | 719 | * |
@@ -697,9 +723,10 @@ cfs_deinit_decompressor_zlib (struct CompressedFileSource *cfs) | |||
697 | static int | 723 | static int |
698 | cfs_deinit_decompressor_bz2 (struct CompressedFileSource *cfs) | 724 | cfs_deinit_decompressor_bz2 (struct CompressedFileSource *cfs) |
699 | { | 725 | { |
700 | LOG ("bz2 decompression not implemented\n"); | 726 | BZ2_bzDecompressEnd (&cfs->bstrm); |
701 | return -1; | 727 | return 1; |
702 | } | 728 | } |
729 | #endif | ||
703 | 730 | ||
704 | 731 | ||
705 | /** | 732 | /** |
@@ -713,10 +740,14 @@ cfs_deinit_decompressor (struct CompressedFileSource *cfs) | |||
713 | { | 740 | { |
714 | switch (cfs->compression_type) | 741 | switch (cfs->compression_type) |
715 | { | 742 | { |
743 | #if HAVE_ZLIB | ||
716 | case COMP_TYPE_ZLIB: | 744 | case COMP_TYPE_ZLIB: |
717 | return cfs_deinit_decompressor_zlib (cfs); | 745 | return cfs_deinit_decompressor_zlib (cfs); |
746 | #endif | ||
747 | #if HAVE_LIBBZ2 | ||
718 | case COMP_TYPE_BZ2: | 748 | case COMP_TYPE_BZ2: |
719 | return cfs_deinit_decompressor_bz2 (cfs); | 749 | return cfs_deinit_decompressor_bz2 (cfs); |
750 | #endif | ||
720 | default: | 751 | default: |
721 | LOG ("invalid compression type selected\n"); | 752 | LOG ("invalid compression type selected\n"); |
722 | return -1; | 753 | return -1; |
@@ -775,6 +806,7 @@ cfs_new (struct BufferedFileDataSource *bfds, | |||
775 | } | 806 | } |
776 | 807 | ||
777 | 808 | ||
809 | #if HAVE_ZLIB | ||
778 | /** | 810 | /** |
779 | * Fills 'data' with new uncompressed data. Does the actual | 811 | * Fills 'data' with new uncompressed data. Does the actual |
780 | * decompression. Will set uncompressed_size on the end of compressed | 812 | * decompression. Will set uncompressed_size on the end of compressed |
@@ -854,8 +886,10 @@ cfs_read_zlib (struct CompressedFileSource *cfs, | |||
854 | cfs->uncompressed_size = cfs->fpos; | 886 | cfs->uncompressed_size = cfs->fpos; |
855 | return rc; | 887 | return rc; |
856 | } | 888 | } |
889 | #endif | ||
857 | 890 | ||
858 | 891 | ||
892 | #if HAVE_LIBBZ2 | ||
859 | /** | 893 | /** |
860 | * Fills 'data' with new uncompressed data. Does the actual | 894 | * Fills 'data' with new uncompressed data. Does the actual |
861 | * decompression. Will set uncompressed_size on the end of compressed | 895 | * decompression. Will set uncompressed_size on the end of compressed |
@@ -874,6 +908,7 @@ cfs_read_bz2 (struct CompressedFileSource *cfs, | |||
874 | LOG ("bz2 decompression not implemented\n"); | 908 | LOG ("bz2 decompression not implemented\n"); |
875 | return -1; | 909 | return -1; |
876 | } | 910 | } |
911 | #endif | ||
877 | 912 | ||
878 | 913 | ||
879 | /** | 914 | /** |
@@ -893,10 +928,14 @@ cfs_read (struct CompressedFileSource *cfs, | |||
893 | { | 928 | { |
894 | switch (cfs->compression_type) | 929 | switch (cfs->compression_type) |
895 | { | 930 | { |
931 | #if HAVE_ZLIB | ||
896 | case COMP_TYPE_ZLIB: | 932 | case COMP_TYPE_ZLIB: |
897 | return cfs_read_zlib (cfs, data, size); | 933 | return cfs_read_zlib (cfs, data, size); |
934 | #endif | ||
935 | #if HAVE_LIBBZ2 | ||
898 | case COMP_TYPE_BZ2: | 936 | case COMP_TYPE_BZ2: |
899 | return cfs_read_bz2 (cfs, data, size); | 937 | return cfs_read_bz2 (cfs, data, size); |
938 | #endif | ||
900 | default: | 939 | default: |
901 | LOG ("invalid compression type selected\n"); | 940 | LOG ("invalid compression type selected\n"); |
902 | return -1; | 941 | return -1; |