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.
Registry archives almost always wrap their contents in a single root directory, and the name differs per ecosystem:
package/flask-3.0.3/serde-1.0.210/rails-7.1.3/To get a useful
fs.FSout of any of these, the caller has to know the root name before callingOpenBytesWithPrefix. 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 aList()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:
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.