package rpmfile-unix
Install
    
    dune-project
 Dependency
Authors
Maintainers
Sources
md5=355d4f9633290f3e5ceb1e9bb099dce9
    
    
  sha512=5d39fa3febac8d5833d00dc373a510c552c5e6c1149f468d713302d2f828d9427f82851262eaebd63fae16866ab3c1b7f563a4f77b93a26f59f6d9d6cb3a1a8a
    
    
  doc/README.html
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-eioUsage
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 | 
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 metadataCustom selector
You may write your own selector.
module My_custom_selector : Rpmfile.Selector.S = struct
  (* ... *)
endManual 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.sizeLimitations
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
- Package File Format, V4 Package format
- Related - Alternative my implementation in TypeScript — rpm-parser
- Live coding stream (in Russian) demo version of the parser