package exportdata

import "internal/exportdata"

Package exportdata implements common utilities for finding and reading gc-generated object files.

Index

Functions

func FindPackageDefinition

func FindPackageDefinition(r *bufio.Reader) (size int, err error)

FindPackageDefinition positions the reader r at the beginning of a package definition file ("__.PKGDEF") within a GC-created archive by reading from it, and returns the size of the package definition file in the archive.

The reader must be positioned at the start of the archive file before calling this function, and "__.PKGDEF" is assumed to be the first file in the archive.

See cmd/internal/archive for details on the archive format.

func FindPkg

func FindPkg(path, srcDir string) (filename, id string, err error)

FindPkg returns the filename and unique package id for an import path based on package information provided by build.Import (using the build.Default build.Context). A relative srcDir is interpreted relative to the current working directory.

func ReadExportDataHeader

func ReadExportDataHeader(r *bufio.Reader) (n int, err error)

ReadExportDataHeader reads the export data header and format from r. It returns the number of bytes read, or an error if the format is no longer supported or it failed to read.

The only currently supported format is binary export data in the unified export format.

func ReadObjectHeaders

func ReadObjectHeaders(r *bufio.Reader) (objapi string, headers []string, err error)

ReadObjectHeaders reads object headers from the reader. Object headers are lines that do not start with an end-of-section marker "$$". The first header is the objabi header. On success, the reader will be positioned at the beginning of the end-of-section marker.

It returns an error if any header does not fit in r.Size() bytes.

func ReadUnified

func ReadUnified(r *bufio.Reader) (data []byte, err error)

ReadUnified reads the contents of the unified export data from a reader r that contains the contents of a GC-created archive file.

On success, the reader will be positioned after the end-of-section marker "\n$$\n".

Supported GC-created archive files have 4 layers of nesting:

Putting this together, the bytes in a GC-created archive files are expected to look like the following. See cmd/internal/archive for more details on ar file headers.

| <!arch>\n | ar file signature | __.PKGDEF...size...\n | ar header for __.PKGDEF including size. | go object <...>\n | objabi header | <optional headers>\n | other headers such as build id | $$B\n | binary format marker | u<data>\n | unified export <data> | $$\n | end-of-section marker | [optional padding] | padding byte (0x0A) if size is odd | [ar file header] | other ar files | [ar file data] |

Source Files

exportdata.go support.go

Version
v1.24.0-rc.3
Published
Jan 31, 2025
Platform
js/wasm
Imports
13 packages
Last checked
51 seconds ago

Tools for package owners.