Page
Library
Module
Module type
Parameter
Class
Class type
Source
A library for reading metadata from RPM packages (supports version 3.0 and partially 4.0).
You can install the library using OPAM package manager:
$ opam install rpmfile
$ opam install # rpmfile-unix / rpmfile-eio
The Rpmfile
module only provides types and functions for easy field access. To read packages you need to use readers.
Package | Description | Require OCaml |
---|---|---|
| Original reader (since the first version) powered by Angstrom | > 4.14 |
| New Eio-based reader for more modern age | > 5.1 |
Each RPM package consists of four sections: lead, signature, header, and payload. The first three are meta information about the package. It contains a description, a dependency list, and so on.
The information in the signature and header is stored on a key-value basis, where the key is called a tag. The value can be a number, a string or an array.
Often you don't need all information about a package, but only some tags. For this task, a selector (predicate function) is used to determine which tags should be parsed and which should not. This greatly increases parsing speed and saves memory.
For an example, let's use the Rpmfile_unix
reader.
(* Create a reader to read all tags. *)
module Rpm_pkg_reader = Rpmfile_unix.Reader.Make (Rpmfile.Selector.All)
let () =
let metadata =
Rpm_pkg_reader.of_file "hello-2.12.1-1.7.x86_64.rpm"
|> Result.get_ok
in
(* Get the package name by field access function. *)
Printf.printf "Package Name: %s\n" @@ Rpmfile.name metadata
You may write your own selector.
module My_custom_selector : Rpmfile.Selector.S = struct
(* ... *)
end
You can write your own decoder if there is no convenient field access function for the tag you need.
let get_signature_size_field =
Rpmfile.get_from_signature
~msg:"signature.size" (* Failwith message. *)
D.int Tag.Signature.size
The implementation uses native OCaml int (32/64 bit depending on your machine) for some internal service values (e.g. as an offset), which may have limitations.
Also, decoding values with field access functions converts any int to native int, which may break on 32-bit systems.
See the API references.
The project is stable, but the library could be more complete. I look forward to your pull requests! If you encounter a bug, then please create an issue.
Related