Documentation
¶
Overview ¶
Package compactindex parses, validates, merges and renders the RubyGems compact index (https://guides.rubygems.org/rubygems-org-compact-index-api/): the versions file, the per-gem info files and the names file that bundler and gem read, plus the request paths of a gem server. Proxy and group repositories of the rubygems format are built on it.
Index ¶
- Constants
- Variables
- func CanonicalPath(rel string) string
- func DigestValue(sum []byte) string
- func InfoMD5(info []byte) string
- func ParseNames(r io.Reader) ([]string, error)
- func RenderInfo(lines []InfoLine) []byte
- func RenderNames(names []string) []byte
- func ValidName(s string) bool
- func ValidSHA256(s string) bool
- func ValidVersionField(s string) bool
- func VerifyInfo(r io.Reader) error
- func VerifyNames(r io.Reader) error
- func VerifyVersions(r io.Reader) error
- type Entry
- type FileSplit
- type InfoLine
- type Kind
- type Path
- type Versions
Constants ¶
const ( // MaxInfoBytes bounds one info file read into memory. MaxInfoBytes = 64 << 20 // MaxLineBytes bounds one line of any compact index file. MaxLineBytes = 4 << 20 // MaxVersionsBytes bounds a versions file read into memory. MaxVersionsBytes = 512 << 20 )
Size limits. The largest real info file is a few MiB (thousands of versions); rubygems.org's versions file is tens of MiB.
Variables ¶
var ErrMalformed = errors.New("malformed compact index")
ErrMalformed is returned for a body that is not a compact index file.
Functions ¶
func CanonicalPath ¶ added in v0.21.0
CanonicalPath maps the "downloads/<file>.gem" alias of a gem download to its "gems/<file>.gem" path and returns every other path unchanged. Hermeto rewrites rubygems.org gem URLs (https://rubygems.org/downloads/<file>.gem) to the proxy it is given, so the alias must reach every repository type the way "gems/" does.
func DigestValue ¶
DigestValue is the Digest and Repr-Digest header value for content whose SHA-256 is sum, spelled the way rubygems.org sends it (a quoted base64 string); bundler checks the file it assembled from ranges against it.
func InfoMD5 ¶
InfoMD5 is the checksum the versions file lists for an info file: the lowercase hex MD5 of its bytes.
func ParseNames ¶
ParseNames reads a names file: "---" and one gem name per line.
func RenderNames ¶
RenderNames writes the sorted, de-duplicated names as a names file.
func ValidName ¶
ValidName reports whether s can be a gem name in a request path or index line: RubyGems accepts letters, digits, dot, underscore and hyphen (rubygems.org even lists names such as "-" and ".cat"); "." and ".." are never a name.
func ValidSHA256 ¶
ValidSHA256 reports whether s is a lowercase hex SHA-256.
func ValidVersionField ¶
ValidVersionField reports whether s is "<version>" and "<version>-<platform>": a digit first (a Gem::Version), then name characters.
func VerifyInfo ¶
VerifyInfo checks that r is a well-formed info file.
func VerifyNames ¶
VerifyNames checks that r is a well-formed names file without holding it in memory.
func VerifyVersions ¶
VerifyVersions checks that r is a well-formed versions file without holding it in memory.
Types ¶
type Entry ¶
Entry is the state of one gem in a versions file: its live versions (yanked ones removed) and the MD5 of its info file as of the last line that named it.
type FileSplit ¶
type FileSplit struct {
// Name is the gem name.
Name string
// Version is the info file's first field for the file: the version, then
// "-<platform>" for a platform gem.
Version string
}
FileSplit is one reading of a gem file name.
func SplitFile ¶
SplitFile returns every way "<name>-<version>[-<platform>]" can be read, in order of increasing name length. Gem names and platforms may hold hyphens and versions never do, so each hyphen followed by a digit is a candidate boundary; the candidates of the real gem server are told apart by looking them up.
type InfoLine ¶
type InfoLine struct {
Raw string
// Version is the first field: the version, followed by "-<platform>" for a
// platform gem. It equals the gem's file name without "<name>-" and ".gem".
Version string
// Checksum is the lowercase hex SHA-256 of the .gem file, "" if the line
// carries none.
Checksum string
}
InfoLine is one line of a gem's info file: "<version>[-<platform>] <dependencies>|<requirements>". Raw is the line exactly as read, without its newline, so merging and re-rendering never rewrite what a member said.
func MergeInfo ¶
MergeInfo is the union of the info lines of several sources by version field: the first source that lists a version provides its line, and the lines keep the order of their first appearance.
func ParseInfoBytes ¶
ParseInfoBytes is ParseInfo for a body in memory.
type Kind ¶
type Kind int
Kind is the type of a gem server request path.
const ( // KindVersions is "versions". KindVersions Kind = iota // KindNames is "names". KindNames // KindInfo is "info/<gem>". KindInfo // KindGem is "gems/<name>-<version>[-<platform>].gem". KindGem // KindGemspec is "quick/Marshal.4.8/<name>-<version>[-<platform>].gemspec.rz". KindGemspec // KindSpecs is one of the legacy Marshal indexes (specs.4.8.gz, // latest_specs.4.8.gz, prerelease_specs.4.8.gz). KindSpecs )
type Path ¶
type Path struct {
Kind Kind
// Gem is the gem of a KindInfo path.
Gem string
// File is the "<name>-<version>[-<platform>]" of a KindGem or KindGemspec
// path, and the file name of a KindSpecs path.
File string
}
Path is a parsed gem server request path.
type Versions ¶
type Versions struct {
// CreatedAt is the "created_at" header value, "" if absent.
CreatedAt string
Entries []Entry
}
Versions is a parsed versions file, one entry per gem.
func ParseVersions ¶
ParseVersions reads a versions file: a header ending at "---" and then lines "<name> <version>,<version>,-<yanked> <info md5>". A gem may appear on several lines (the file is append-only): their versions accumulate, a "-" version removes it, and the last MD5 wins. Entries keep the order of first appearance.