Skip to content
Snippets Groups Projects
Commit ef895567 authored by jrayner's avatar jrayner
Browse files

add integrity check option

parent 5b60dd3f
Branches
No related tags found
No related merge requests found
......@@ -85,13 +85,14 @@ static int bgzip_main_usage(void)
fprintf(stderr, " -g, --rebgzip use an index file to bgzip a file\n");
fprintf(stderr, " -s, --size INT decompress INT bytes (uncompressed size)\n");
fprintf(stderr, " -@, --threads INT number of compression threads to use [1]\n");
fprintf(stderr, " -t, --test test integrity of compressed file");
fprintf(stderr, "\n");
return 1;
}
int main(int argc, char **argv)
{
int c, compress, compress_level = -1, pstdout, is_forced, index = 0, rebgzip = 0, reindex = 0;
int c, compress, compress_level = -1, pstdout, is_forced, test, index = 0, rebgzip = 0, reindex = 0;
BGZF *fp;
void *buffer;
long start, end, size;
......@@ -112,12 +113,13 @@ int main(int argc, char **argv)
{"rebgzip",no_argument,NULL,'g'},
{"size", required_argument, NULL, 's'},
{"threads", required_argument, NULL, '@'},
{"test", no_argument, NULL, 't'},
{"version", no_argument, NULL, 1},
{NULL, 0, NULL, 0}
};
compress = 1; pstdout = 0; start = 0; size = -1; end = -1; is_forced = 0;
while((c = getopt_long(argc, argv, "cdh?fb:@:s:iI:l:gr",loptions,NULL)) >= 0){
compress = 1; pstdout = 0; start = 0; size = -1; end = -1; is_forced = 0; test = 0;
while((c = getopt_long(argc, argv, "cdh?fb:@:s:iI:l:grt",loptions,NULL)) >= 0){
switch(c){
case 'd': compress = 0; break;
case 'c': pstdout = 1; break;
......@@ -130,6 +132,7 @@ int main(int argc, char **argv)
case 'g': rebgzip = 1; break;
case 'r': reindex = 1; compress = 0; break;
case '@': threads = atoi(optarg); break;
case 't': test = 1; compress = 0; reindex = 0; break;
case 1:
printf(
"bgzip (htslib) %s\n"
......@@ -303,7 +306,7 @@ int main(int argc, char **argv)
return 1;
}
if (pstdout) {
if (pstdout || test) {
f_dst = fileno(stdout);
}
else {
......@@ -350,17 +353,19 @@ int main(int argc, char **argv)
if (c == 0) break;
if (c < 0) error("Could not read %d bytes: Error %d\n", (end - start > WINDOW_SIZE)? WINDOW_SIZE:(end - start), fp->errcode);
start += c;
if ( !test ) {
if ( write(f_dst, buffer, c) != c ) {
#ifdef _WIN32
if (GetLastError() != ERROR_NO_DATA)
#endif
error("Could not write %d bytes\n", c);
}
}
if (end >= 0 && start >= end) break;
}
free(buffer);
if (bgzf_close(fp) < 0) error("Close failed: Error %d\n",fp->errcode);
if (!pstdout) unlink(argv[optind]);
if (!pstdout && !test) unlink(argv[optind]);
return 0;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment