internal

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Download

func Download(ctx context.Context, url, path string, onProgress func(current, total int64)) error

Download downloads a file from a given URL to a specified path with context support. If the download fails, any partially created file at the destination path will be removed.

func ExtractJSONKeys

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

ExtractJSONKeys extracts the top-level keys from a JSON object provided by an io.Reader.

It expects the input to be a valid JSON object (i.e., starting with '{'). The function iterates through all key-value pairs at the top level, collects the keys in the order they appear in the JSON string, and skips the values.

Parameters:

  • r: an io.Reader containing the JSON object.

Returns:

  • []string: a slice of strings containing the keys found at the top level of the JSON object, in the same order as in the input JSON.
  • error: an error if the input is not a valid JSON object or if any decoding issues occur.

func FetchJSON

func FetchJSON[T any](ctx context.Context, url string, value *T) error

FetchJSON fetches JSON data from the given URL and decodes it into the provided variable with context support.

Parameters:

  • ctx: the context to control the request lifetime.
  • url: the URL to fetch the JSON from.
  • value: a pointer to the variable where the decoded JSON will be stored.

Returns:

  • error: an error if the HTTP request fails or the JSON cannot be decoded.

func MergeZips

func MergeZips(ctx context.Context, baseZipPath, overlayZipPath, outputZipPath string) (err error)

MergeZips combines two zip archives. It overlays the files from overlayZipPath on top of baseZipPath. If a file exists in both archives, the one from overlayZipPath is used in the final outputZipPath.

Types

type ProgressReader

type ProgressReader struct {
	io.Reader

	Total      int64
	Current    int64
	OnProgress func(current, total int64)
}

ProgressReader implements io.Reader to track download progress. It invokes a callback function with the number of bytes read.

func (*ProgressReader) Read

func (pr *ProgressReader) Read(p []byte) (int, error)

Read implements the io.Reader interface. It reads into p, updates the current progress, and invokes the OnProgress callback.

Jump to

Keyboard shortcuts

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