fz_document * fz_open_document_with_stream(fz_context *ctx, char *magic, fz_stream *stream) { char *ext = strrchr(magic, '.'); if (ext) { if (!fz_strcasecmp(ext, ".xps") || !fz_strcasecmp(ext, ".rels")) return (fz_document*) xps_open_document_with_stream(ctx, stream); if (!fz_strcasecmp(ext, ".cbz") || !fz_strcasecmp(ext, ".zip")) return (fz_document*) cbz_open_document_with_stream(ctx, stream); if (!fz_strcasecmp(ext, ".pdf")) return (fz_document*) pdf_open_document_with_stream(ctx, stream); } if (!strcmp(magic, "cbz") || !strcmp(magic, "application/x-cbz")) return (fz_document*) cbz_open_document_with_stream(ctx, stream); if (!strcmp(magic, "xps") || !strcmp(magic, "application/vnd.ms-xpsdocument")) return (fz_document*) xps_open_document_with_stream(ctx, stream); if (!strcmp(magic, "pdf") || !strcmp(magic, "application/pdf")) return (fz_document*) pdf_open_document_with_stream(ctx, stream); /* last guess: pdf */ return (fz_document*) pdf_open_document_with_stream(ctx, stream); }
cbz_document * cbz_open_document(fz_context *ctx, const char *filename) { fz_stream *file; cbz_document *doc; file = fz_open_file(ctx, filename); if (!file) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot open file '%s': %s", filename, strerror(errno)); fz_try(ctx) { doc = cbz_open_document_with_stream(ctx, file); } fz_always(ctx) { fz_close(file); } fz_catch(ctx) { fz_rethrow(ctx); } return doc; }
static cbz_document * cbz_open_document(fz_context *ctx, const char *filename) { fz_stream *file; cbz_document *doc; file = fz_open_file(ctx, filename); fz_try(ctx) doc = cbz_open_document_with_stream(ctx, file); fz_always(ctx) fz_drop_stream(ctx, file); fz_catch(ctx) fz_rethrow(ctx); return doc; }