diff --git a/bgzf.c b/bgzf.c index 8092c7b9a..2c224b21b 100644 --- a/bgzf.c +++ b/bgzf.c @@ -548,6 +548,10 @@ BGZF *bgzf_hopen(hFILE *hfp, const char *mode) } #ifdef HAVE_LIBDEFLATE +uint32_t hts_crc32(uint32_t crc, const void *buf, size_t len) { + return libdeflate_crc32(crc, buf, len); +} + int bgzf_compress(void *_dst, size_t *dlen, const void *src, size_t slen, int level) { if (slen == 0) { @@ -607,6 +611,10 @@ int bgzf_compress(void *_dst, size_t *dlen, const void *src, size_t slen, int le #else +uint32_t hts_crc32(uint32_t crc, const void *buf, size_t len) { + return crc32(crc, buf, len); +} + int bgzf_compress(void *_dst, size_t *dlen, const void *src, size_t slen, int level) { uint32_t crc; diff --git a/htslib/hts.h b/htslib/hts.h index 08bf71c2c..3b6d8b05c 100644 --- a/htslib/hts.h +++ b/htslib/hts.h @@ -1517,6 +1517,14 @@ static inline int hts_bin_level(int bin) { return l; } +/************************************** + * Exposing the CRC32 implementation * + * Either from zlib or libdeflate. * + *************************************/ +HTSLIB_EXPORT +uint32_t hts_crc32(uint32_t crc, const void *buf, size_t len); + + //! Compute the corresponding entry into the linear index of a given bin from //! a binning index /*!