@@ -783,20 +783,35 @@ static void squash_qual(cram_block *b) {
783783 */
784784static int cram_compress_slice (cram_fd * fd , cram_container * c , cram_slice * s ) {
785785 int level = fd -> level , i ;
786- int method = 1 <<GZIP | 1 <<GZIP_RLE , methodF = method , qmethod , qmethodF ;
786+ int64_t method = 1 <<GZIP | 1 <<GZIP_RLE , methodF = method , qmethod , qmethodF ;
787+ int v31_or_above = (fd -> version >= (3 <<8 )+ 1 );
787788
788789 /* Compress the CORE Block too, with minimal zlib level */
789790 if (level > 5 && s -> block [0 ]-> uncomp_size > 500 )
791+ #ifdef HAVE_ZSTD
792+ cram_compress_block (fd , s , s -> block [0 ], NULL , 1 <<ZSTD , 3 );
793+ #else
790794 cram_compress_block (fd , s , s -> block [0 ], NULL , 1 <<GZIP , 1 );
795+ #endif
791796
792797 if (fd -> use_bz2 )
793798 method |= 1 <<BZIP2 ;
794799
795800#ifdef HAVE_LIBBSC
796- if (fd -> use_bsc )
801+ if (fd -> use_bsc && v31_or_above )
797802 method |= 1 <<BSC ;
798803#endif
799804
805+ #ifdef HAVE_ZSTD
806+ if (fd -> use_zstd && v31_or_above ) {
807+ method |= (1 <<ZSTD );
808+ methodF |= (1 <<ZSTD );
809+
810+ method &= ~((1 <<GZIP ) | (1 <<GZIP_RLE ) | (1 <<GZIP_1 ));
811+ methodF &= ~((1 <<GZIP ) | (1 <<GZIP_RLE ) | (1 <<GZIP_1 ));
812+ }
813+ #endif
814+
800815 int method_rans = (1 <<RANS0 ) | (1 <<RANS1 );
801816 int method_ranspr = method_rans ;
802817 if (fd -> use_rans ) {
@@ -809,20 +824,19 @@ static int cram_compress_slice(cram_fd *fd, cram_container *c, cram_slice *s) {
809824 method_ranspr |= (1 <<RANS_PR129 ) | (1 <<RANS_PR192 );
810825 }
811826
812- int v31_or_above = (fd -> version >= (3 <<8 )+ 1 );
813827 if (fd -> use_rans ) {
814828 methodF |= v31_or_above ? method_ranspr : method_rans ;
815829 method |= v31_or_above ? method_ranspr : method_rans ;
816830 }
817831
818- int method_arith = 0 ;
832+ int64_t method_arith = 0 ;
819833 if (fd -> use_arith ) {
820834 method_arith = (1 <<ARITH_PR0 ) | (1 <<ARITH_PR1 );
821835 if (level > 1 )
822836 method_arith |=
823- (1 <<ARITH_PR64 ) | (1 <<ARITH_PR9 )
824- | (1 <<ARITH_PR128 ) | (1 <<ARITH_PR129 )
825- | (1 <<ARITH_PR192 ) | (1 <<ARITH_PR193 );
837+ (1LL <<ARITH_PR64 ) | (1LL <<ARITH_PR9 )
838+ | (1LL <<ARITH_PR128 ) | (1LL <<ARITH_PR129 )
839+ | (1LL <<ARITH_PR192 ) | (1LL <<ARITH_PR193 );
826840 }
827841 if (fd -> use_arith && v31_or_above ) {
828842 methodF |= method_arith ;
@@ -835,12 +849,23 @@ static int cram_compress_slice(cram_fd *fd, cram_container *c, cram_slice *s) {
835849 /* Faster method for data series we only need entropy encoding on */
836850 methodF = method & ~(1 <<GZIP | 1 <<BZIP2 | 1 <<LZMA );
837851 if (level >= 5 ) {
838- method |= 1 <<GZIP_1 ;
852+ #ifdef HAVE_ZSTD
853+ if (fd -> use_zstd && v31_or_above )
854+ method |= 1LL <<ZSTD_1 ;
855+ else
856+ #else
857+ method |= 1 <<GZIP_1 ;
858+ #endif
839859 methodF = method ;
840860 }
841861 if (level == 1 ) {
842- method &= ~(1 <<GZIP );
843- method |= 1 <<GZIP_1 ;
862+ #ifdef HAVE_ZSTD
863+ if (fd -> use_zstd && v31_or_above )
864+ method = (method & ~(1 <<ZSTD )) | (1LL <<ZSTD_1 );
865+ else
866+ #else
867+ method = (method & ~(1 <<GZIP )) | (1LL <<GZIP_1 );
868+ #endif
844869 methodF = method ;
845870 }
846871
0 commit comments