swh.loader.core.nar module#

class swh.loader.core.nar.Nar(hash_names: List[str], format_output: str = 'hex', exclude_vcs: bool = False, vcs_type: str | None = 'git', debug: bool = False)[source]#

Bases: object

NAR serializer.

This builds the NAR structure and serializes it as per the phd thesis from Eelco Dolstra thesis. See https://edolstra.github.io/pubs/phd-thesis.pdf.

For example, this tree on a filesystem:

$ tree foo
foo
├── bar
│   └── exe
└── baz

1 directory, 2 files

serializes as:

nix-archive-1(typedirectoryentry(namebarnode(typedirectoryentry(nameexenode(typeregularexecutablecontents<Content of file foo/bar/exe>))))entry(namebaznode(typeregularcontents<Content of file foo/baz>)))

For reability, the debug mode prints the following:

nix-archive-1
  (
  type
  directory
    entry
    (
    name
    bar
    node
      (
      type
      directory
        entry
        (
        name
        exe
        node
          (
          type
          regular
          executable

          contents
          <Content of file foo/bar/exe>
          )
        )
      )
    )
    entry
    (
    name
    baz
    node
      (
      type
      regular
      contents
      <Content of file foo/baz>
     )
   )
 )

Note: “<Content of file $name>” is a placeholder for the actual file content

str_(thing)[source]#

Compute the nar serialization format on ‘thing’ and compute its hash.

This is the function named named ‘str’ in Figure 5.2 p.93 (page 101 of pdf) [1]

[1] https://edolstra.github.io/pubs/phd-thesis.pdf

update(chunk)[source]#
serialize(fso: Path) None[source]#
digest() Dict[str, bytes][source]#

Compute the hash results with bytes format.

hexdigest() Dict[str, str][source]#

Compute the hash results with hex format.

b64digest() Dict[str, str][source]#

Compute the hash results with b64 format.

b32digest() Dict[str, str][source]#

Compute the hash results with b32 format.