X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bgzf.c;fp=bgzf.c;h=2cd1c5e514a94c5569f5819c7f6b23af8985d444;hb=8a9ee843efcc2ec0cfb553d0b571536cf621864d;hp=71d8c81460044cb8b88c655d41ba918874641f61;hpb=9bd8cd7dd42efa091a9361bb06a29d1bead405ce;p=samtools.git diff --git a/bgzf.c b/bgzf.c index 71d8c81..2cd1c5e 100644 --- a/bgzf.c +++ b/bgzf.c @@ -571,6 +571,14 @@ bgzf_close(BGZF* fp) if (flush_block(fp) != 0) { return -1; } + { // add an empty block + int count, block_length = deflate_block(fp, 0); +#ifdef _USE_KNETFILE + count = fwrite(fp->compressed_block, 1, block_length, fp->x.fpw); +#else + count = fwrite(fp->compressed_block, 1, block_length, fp->file); +#endif + } #ifdef _USE_KNETFILE if (fflush(fp->x.fpw) != 0) { #else @@ -610,6 +618,25 @@ void bgzf_set_cache_size(BGZF *fp, int cache_size) if (fp) fp->cache_size = cache_size; } +int bgzf_check_EOF(BGZF *fp) +{ + static uint8_t magic[28] = "\037\213\010\4\0\0\0\0\0\377\6\0\102\103\2\0\033\0\3\0\0\0\0\0\0\0\0\0"; + uint8_t buf[28]; + off_t offset; +#ifdef _USE_KNETFILE + offset = knet_tell(fp->x.fpr); + if (knet_seek(fp->x.fpr, -28, SEEK_END) != 0) return -1; + knet_read(fp->x.fpr, buf, 28); + knet_seek(fp->x.fpr, offset, SEEK_SET); +#else + offset = ftello(fp->file); + if (fseeko(fp->file, -28, SEEK_END) != 0) return -1; + fread(buf, 1, 28, fp->file); + fseeko(fp->file, offset, SEEK_SET); +#endif + return (memcmp(magic, buf, 28) == 0)? 1 : 0; +} + int64_t bgzf_seek(BGZF* fp, int64_t pos, int where) { @@ -636,4 +663,3 @@ bgzf_seek(BGZF* fp, int64_t pos, int where) fp->block_offset = block_offset; return 0; } -