package rpmfile-eio

  1. Overview
  2. Docs
RPM package metadata reader (powered by Eio)

Install

Dune Dependency

Authors

Maintainers

Sources

0.5.tar.gz
md5=4175664de64bf013df018dcca94078ae
sha512=4bd49790d52bbdf56d2684a5be4d1df3276a73e387b079354fcdc2276550a372137d2b1a9d5b41902fa470630416257d7e6d3c1359768e5121a0b8bc501945c7

README.md.html

rpmfile

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

Usage

The rpmfile package only provides types and functions for easy field access.

To read RPM files, you need to use a package that implements a reader.

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

Installation

You can install the library using OPAM package manager:

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

Also, you may want to use the development (upstream) version of the library, but be careful:

$ opam pin rpmfile-*.dev https://github.com/dx3mod/rpmfile.git

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 (like 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
Or just use built-in selectors
Selector For
Selector.All read all tags
Selector.Base read basic tags (see docs or implementation)

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

Lwt

For how to read from a Lwt channel, see the example.

Read by chunk

See the Angstrom.Unbuffered module.

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 OCaml int, which may break on 32-bit systems.

CLI

You can use the rpmfile-unix package as a command line utility to get basic information about the package, similar to rpm -qi.

Example
$ rpmfile-unix test_misc/hello-2.12.1-1.7.x86_64.rpm
Name        : hello                 
Version     : 2.12.1
Release     : 1.7
Architecture: x86_64
Group       : Development/Tools/Other
Size        : 185847
License     : GPL-3.0-or-later
Source RPM  : hello-2.12.1-1.7.src.rpm
Build Date  : 2022-05-30
Build Host  : reproducible
Packager    : https://bugs.opensuse.org
Vendor      : openSUSE
URL         : https://www.gnu.org/software/hello
Summary     : A Friendly Greeting Program
Description :
The GNU hello program produces a familiar, friendly greeting.  It
allows nonprogrammers to use a classic computer science tool that would
otherwise be unavailable to them.  Because it is protected by the GNU
General Public License, users are free to share and change it.

GNU hello supports many native languages.
Distribution: openSUSE Tumbleweed

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.

See HACKING.md if you are interested in developing the project.

OCaml

Innovation. Community. Security.