package rpmfile

  1. Overview
  2. Docs
RPM package metadata reader

Install

Dune Dependency

Authors

Maintainers

Sources

0.3.tar.gz
md5=3cb6a60280cc72dcaed5aa8172c0c89e
sha512=8a8c86f4c23e47098108cc70bb3c2c6aa05fa6560221426ab7ea6e6f3722a9fe851085b5bd53cf829707bc1898f4f1929ae0cd33735c4bc3102ded49302ee98d

Description

Tags

rpm parser rpmfile

Published: 16 Aug 2024

README

rpmfile

A library for reading metadata from RPM packages (supports version 3.0 and partially 4.0).

Installation

You can install the library using OPAM package manager:

$ opam install rpmfile
$ opam install # rpmfile-unix / rpmfile-eio

Usage

The Rpmfile module only provides types and functions for easy field access. To read packages you need to use readers.

Package Description Require OCaml
rpmfile-unix Original reader (since the first version) powered by Angstrom > 4.14
rpmfile-eio New Eio-based reader for more modern age > 5.1

Theoretical minimum

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.

Read package

For an example, let's use the Rpmfile_unixreader.

(* 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

Custom selector

You may write your own selector.

module My_custom_selector : Rpmfile.Selector.S = struct
  (* ... *)
end

Manual decode

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

Limitations

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.

Documentation

See the API references.

Contribution

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.

References

Dependencies (2)

  1. dune >= "3.16"
  2. ocaml > "4.14"

Dev Dependencies (1)

  1. odoc with-doc

Used by (2)

  1. rpmfile-eio < "0.4.0"
  2. rpmfile-unix

Conflicts

None

OCaml

Innovation. Community. Security.