utils

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

utility package for nvm/utils

Useful only for nvm (not the nvm-shim)

Index

Constants

View Source
const INDEX = "index.tab"
View Source
const SHASUMS = "SHASUMS256.txt"

remote filename which indicates sha's for each downloadable file

Variables

View Source
var BASE_URL = os.Getenv("NVM_NODEJS_ORG_MIRROR")

NVM_NODEJS_ORG_MIRROR - base url for downloading node; default: "https://nodejs.org/dist"

View Source
var CI = os.Getenv("CI")

CI usually sets CI=true? disable progress bars?

View Source
var ErrInvalidSha = errors.New("invalid sha")

error when verified sha did not match calculated file

View Source
var ErrNoNvmRc = errors.New("no .nvmrc found")
View Source
var ErrShaNotFound = errors.New("sha not found")

error when filename/sha not found

View Source
var Writer = tabwriter.NewWriter(os.Stderr, 1, 1, 4, ' ', 0)

customized writer to print help logs nicely

Functions

func CheckSha added in v0.1.4

func CheckSha(node_body []byte, sha string) (err error)

gets file sha and checks against a verified sha returns ErrInvalidSha

func DownloadNode added in v0.1.5

func DownloadNode(url string) (b []byte, err error)

func FetchSha added in v0.1.5

func FetchSha(url, filename string) (sha string, err error)

downloads shasums and gets verified sha for a filename

func FlushTabs

func FlushTabs()

flush tabbed output to stdout

func GetDownloadUrl added in v0.1.4

func GetDownloadUrl(v common.Version, d exclusive_node_file) string

determine where to download node install files

`v` a verified/parsed version string

`d` is a [commands.NodeDownload]

used by [commands.Install]

func GetInstalledVersions added in v0.1.6

func GetInstalledVersions() (versions []common.Version, err error)

func GetLTS added in v0.1.5

func GetLTS() (out common.Version, err error)

version is non-specific and we need to query the releases to find the latest version which fits the range

func GetLatestFromVersion added in v0.1.5

func GetLatestFromVersion(version common.Version) (out common.Version, err error)

version is non-specific and we need to query the releases to find the latest version which fits the range

func GetOsAndArch added in v0.1.4

func GetOsAndArch() (remote_os, remote_arch string)

TODO: this can be cached, or run once used to determine download url in [commands.GetDownloadUrl]

func PrintTabs

func PrintTabs(str string)

aligns tabs with tabwriter

func ProgressBar added in v0.1.5

func ProgressBar(b *[]byte, size int)

show a progress bar in stdout; needs bytes to be written using something like io.Reader.Read

func ReadNvmrc added in v0.1.6

func ReadNvmrc() (ver common.Version, err error)

get version in .nvmrc

func Rename

func Rename(source, target string) (err error)

rename or move file; moving may be required if using a docker container with volumes

func SaveToFile

func SaveToFile(body []byte, filename string) error

save `body` bytes to `filename` TODO: this may be deprecated if we transfer http response directly to file, sha, and progresssbar

func UnGzip

func UnGzip(source, target string) (string, error)

func Untar

func Untar(tarball, target string) error

TODO: gzipping can be done with the tarring: https://cs.opensource.google/go/x/build/+/8c11e572:internal/untar/untar.go reverse the effects of tarring

func ValidateUrl added in v0.1.5

func ValidateUrl(url_str string) (string, error)

check that a url string is valid

Types

type NodeDownload added in v0.1.4

type NodeDownload int

Enum for downloading either node or shasums

const (
	DOWNLOAD_NODE   NodeDownload = iota // downloads node
	DOWNLOAD_SHASUM                     // downloads SHASUMS
)

Jump to

Keyboard shortcuts

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