Skip to content

Add root prefix detection for registry archives #50

Description

@andrew

Registry archives almost always wrap their contents in a single root directory, and the name differs per ecosystem:

  • npm tarball: package/
  • PyPI sdist: flask-3.0.3/
  • crate: serde-1.0.210/
  • GitHub codeload zip: rails-7.1.3/

To get a useful fs.FS out of any of these, the caller has to know the root name before calling OpenBytesWithPrefix. For npm it is fixed, but for the rest it has to be derived from the package name and version, or guessed, or read back out of a List() call and then reopened.

A helper that inspects the entries and reports the single common root directory, if there is exactly one, would cover all of these in one call:

r, _ := archives.OpenBytes(name, buf)
prefix, _ := archives.DetectRootPrefix(r)

It should report no prefix when entries sit at the top level, or when there is more than one root directory, so a caller can pass the result straight through without checking the archive shape first.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions