Source file epubArchiveBase.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(*****************************************************************************)
(*                                                                           *)
(*  Copyright (C) 2024 Yves Ndiaye                                           *)
(*                                                                           *)
(* This Source Code Form is subject to the terms of the Mozilla Public       *)
(* License, v. 2.0. If a copy of the MPL was not distributed with this       *)
(* file, You can obtain one at https://mozilla.org/MPL/2.0/.                 *)
(*                                                                           *)
(*****************************************************************************)

type t = { handler : Zip.in_file; files : string list }

let resolve_path_relative ~file epub filename =
  let toc = List.find (String.ends_with ~suffix:file) epub.files in
  let toc = toc |> Util.Path.of_string |> Util.Path.pop in
  let filename = Util.Path.concat toc (Util.Path.of_string filename) in
  filename |> Util.Path.reduce |> Util.Path.to_string

let resolve_path_relative_to_toc = resolve_path_relative ~file:"toc.ncx"
let resolve_path_relative_to_opf = resolve_path_relative ~file:"content.opf"