bundle

package
v1.11.1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package bundle implements the standalone-binary trailer format and resource collection used by `lg -b`. A standalone binary is the lg executable with a compiled bytecode payload (and optionally a resource archive) appended, followed by a fixed trailer the runtime reads back at startup.

Trailers appended to standalone binaries:

Legacy (no resources): [lgb data][8-byte lgbSize][4-byte 'LGBX']  (12-byte trailer)
v2    (resources):     [lgb data][resource archive][8-byte lgbSize][8-byte resSize][4-byte 'LGB2']  (20-byte trailer)
v3    (store id):      [lgb data][resource archive][store id][8-byte lgbSize][8-byte resSize][8-byte idSize][4-byte 'LGB3']  (28-byte trailer)

A v3 trailer is written whenever the bundle bakes a storage store id (the resource archive is still optional, so resSize may be 0). v2 is written when there are resources but no baked id; resource-less, id-less bundles keep the byte-identical legacy trailer. Readers recognize all three.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendTrailer

func AppendTrailer(out io.Writer, lgbData, resArc []byte, storeID string) error

AppendTrailer writes the bundle payload to out: the lgb bytes, an optional resource archive, an optional baked storage store id, and the matching trailer. A non-empty storeID emits the v3 trailer (resArc still optional); a resource archive with no id emits v2; otherwise the byte-identical legacy trailer. This is the only writer of the trailer format (parseBundleTrailer is the only reader).

func BaseBinarySize

func BaseBinarySize(f *os.File) (int64, error)

BaseBinarySize returns the size of the lg binary without any appended bundle, so re-bundling can strip an existing payload. A corrupt trailer surfaces as an error rather than a silently wrong size.

func CollectResources

func CollectResources(roots []string, excludeAbs string) (map[string][]byte, error)

CollectResources returns a map of slash-relative path → file bytes for every regular file reachable under the resource roots. It follows symlinks everywhere the dev FS provider does (which resolves names with os.Stat) — to symlinked roots, symlinked sub-directories, and symlinked files — so a -b bundle embeds exactly what dev lookup would find. Symlink cycles are guarded by real-path. When the same relative path exists under multiple roots the first root wins (matching the provider's precedence). The bundle's own output file (excludeAbs) is never embedded, so a dst inside a resource root can't embed itself.

func ReadBundled

func ReadBundled(path string) (lgb []byte, res []byte, storeID string)

ReadBundled extracts the appended payload from the file at path. It recognizes the v3 (store-id-carrying), v2 (resource-carrying), and legacy trailers; res is nil for legacy bundles and storeID is "" for any bundle built before v3. Returns nil, nil, "" for a non-bundle or corrupt file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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