X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=tabix.git;a=blobdiff_plain;f=bgzf.c;h=94e6194700f6d9f633939804a7bade4bf58c9df2;hp=7a936a89819176181e23e511a437a12892fbe310;hb=3be5ff47495762af7f2ebec145bc8f9c7674593d;hpb=f14cecb6523bd4275c2858c2d54167c94db25ede diff --git a/bgzf.c b/bgzf.c index 7a936a8..94e6194 100644 --- a/bgzf.c +++ b/bgzf.c @@ -111,6 +111,32 @@ report_error(BGZF* fp, const char* message) { fp->error = message; } +int is_bgzipped(const char *fn) +{ + BGZF *fp; + uint8_t buf[10],magic[10]="\037\213\010\4\0\0\0\0\0\377"; + int n; + + if ((fp = bgzf_open(fn, "r")) == 0) + { + fprintf(stderr, "[is_bgzipped] failed to open the file: %s\n",fn); + return -1; + } + +#ifdef _USE_KNETFILE + n = knet_read(fp->x.fpr, buf, 10); +#else + n = fread(buf, 1, 10, fp->file); +#endif + bgzf_close(fp); + + if ( n!=10 ) + return -1; + + if ( !memcmp(magic, buf, 10) ) return 1; + return 0; +} + static BGZF *bgzf_read_init() { BGZF *fp;