Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions hfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,7 @@ static int init_add_plugin(void *obj, int (*init)(struct hFILE_plugin *),
static int load_hfile_plugins(void)
{
static const struct hFILE_scheme_handler
chunked = { hopen_chunked_manifest, hfile_always_local, "built-in", 80 },
data = { hopen_mem, hfile_always_local, "built-in", 80 },
file = { hopen_fd_fileuri, hfile_always_local, "built-in", 80 },
preload = { hopen_preload, is_preload_url_remote, "built-in", 80 };
Expand All @@ -1119,6 +1120,7 @@ static int load_hfile_plugins(void)
if (schemes == NULL)
return -1;

hfile_add_scheme_handler("chunked", &chunked);
hfile_add_scheme_handler("data", &data);
hfile_add_scheme_handler("file", &file);
hfile_add_scheme_handler("preload", &preload);
Expand Down
4 changes: 4 additions & 0 deletions hfile_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ struct BGZF;
*/
struct hFILE *bgzf_hfile(struct BGZF *fp);

/* Opens chunked: manifests as seekable logical files. */
struct hFILE *hopen_chunked_manifest(const char *url, const char *mode)
HTS_RESULT_USED;

/*!
@abstract Closes all hFILE plugins that have been loaded
*/
Expand Down
13 changes: 10 additions & 3 deletions hts.c
Original file line number Diff line number Diff line change
Expand Up @@ -2827,11 +2827,17 @@ static int idx_save_core(const hts_idx_t *idx, BGZF *fp, int fmt)
int hts_idx_save(const hts_idx_t *idx, const char *fn, int fmt)
{
int ret, save;
const char *fn_local;

if (idx == NULL || fn == NULL) { errno = EINVAL; return -1; }
char *fnidx = (char*)calloc(1, strlen(fn) + 5);

fn_local = strncmp(fn, "chunked:", 8) == 0 && !hisremote(fn + 8)
? fn + 8 : fn;

char *fnidx = (char*)calloc(1, strlen(fn_local) + 5);
if (fnidx == NULL) return -1;

strcpy(fnidx, fn);
strcpy(fnidx, fn_local);
switch (fmt) {
case HTS_FMT_BAI: strcat(fnidx, ".bai"); break;
case HTS_FMT_CSI: strcat(fnidx, ".csi"); break;
Expand Down Expand Up @@ -4776,8 +4782,9 @@ int hts_idx_check_local(const char *fn, int fmt, char **fnidx) {
break;
}
} else {
if (strncmp(fn, "chunked:", 8) == 0 && !hisremote(fn + 8)) fn_tmp = fn + 8;
// Borrowed from hopen_fd_fileuri()
if (strncmp(fn, "file://localhost/", 17) == 0) fn_tmp = fn + 16;
else if (strncmp(fn, "file://localhost/", 17) == 0) fn_tmp = fn + 16;
else if (strncmp(fn, "file:///", 8) == 0) fn_tmp = fn + 7;
else fn_tmp = fn;
#if defined(_WIN32) || defined(__MSYS__)
Expand Down
4 changes: 4 additions & 0 deletions htslib/hfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ The usual `fopen(3)` _mode_ letters are supported: one of
`r` (read), `w` (write), `a` (append), optionally followed by any of
`+` (update), `e` (close on `exec(2)`), `x` (create exclusively),
`:` (indicates scheme-specific variable arguments follow).

The built-in `chunked:` scheme opens a read-only manifest containing one
chunk filename per line and presents the chunks as one seekable logical file.
Blank lines and lines beginning with `#` are ignored.
*/
HTSLIB_EXPORT
hFILE *hopen(const char *filename, const char *mode, ...) HTS_RESULT_USED;
Expand Down
Loading