compactindex

package
v0.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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

func CanonicalPath(rel string) string

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

func DigestValue(sum []byte) string

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

func InfoMD5(info []byte) string

InfoMD5 is the checksum the versions file lists for an info file: the lowercase hex MD5 of its bytes.

func ParseNames

func ParseNames(r io.Reader) ([]string, error)

ParseNames reads a names file: "---" and one gem name per line.

func RenderInfo

func RenderInfo(lines []InfoLine) []byte

RenderInfo writes lines as an info file.

func RenderNames

func RenderNames(names []string) []byte

RenderNames writes the sorted, de-duplicated names as a names file.

func ValidName

func ValidName(s string) bool

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

func ValidSHA256(s string) bool

ValidSHA256 reports whether s is a lowercase hex SHA-256.

func ValidVersionField

func ValidVersionField(s string) bool

ValidVersionField reports whether s is "<version>" and "<version>-<platform>": a digit first (a Gem::Version), then name characters.

func VerifyInfo

func VerifyInfo(r io.Reader) error

VerifyInfo checks that r is a well-formed info file.

func VerifyNames

func VerifyNames(r io.Reader) error

VerifyNames checks that r is a well-formed names file without holding it in memory.

func VerifyVersions

func VerifyVersions(r io.Reader) error

VerifyVersions checks that r is a well-formed versions file without holding it in memory.

Types

type Entry

type Entry struct {
	Name     string
	Versions []string
	InfoMD5  string
}

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

func SplitFile(stem string) []FileSplit

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 FindInfo

func FindInfo(lines []InfoLine, version string) (InfoLine, bool)

FindInfo returns the line of version (the info "version[-platform]" field).

func MergeInfo

func MergeInfo(sources ...[]InfoLine) []InfoLine

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 ParseInfo

func ParseInfo(r io.Reader) ([]InfoLine, error)

ParseInfo reads a gem info file: "---" and one line per version.

func ParseInfoBytes

func ParseInfoBytes(body []byte) ([]InfoLine, error)

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.

func ParsePath

func ParsePath(rel string) (Path, bool)

ParsePath classifies a repository-relative request path; ok is false for anything a gem server does not serve from the root of the index.

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

func ParseVersions(r io.Reader) (*Versions, error)

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.

func (*Versions) Render

func (v *Versions) Render() []byte

Render writes the versions file: the entries sorted by name, one line each; gems without a live version are left out.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL