publicarchive

package
v1.13.4 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2025 License: BSD-3-Clause Imports: 14 Imported by: 0

README

Public Archive Downloader SDK

This Go package provides a utility to download and extract tar archives from public URLs. It's tailored for downloading Lux network archives but can be adapted for other use cases.

Features

  • Downloads files from predefined URLs.
  • Tracks download progress and logs status updates.
  • Safely unpacks .tar archives to a target directory.
  • Includes security checks to prevent path traversal and manage large files.

Usage example

// Copyright (C) 2025, Lux Industries, Inc. All rights reserved
// See the file LICENSE for licensing terms.

package main

import ( "fmt" "os"

"github.com/luxfi/lux-cli/sdk/network"
"github.com/luxfi/luxd/utils/constants"
"github.com/luxfi/luxd/utils/logging"
"github.com/your-repo-name/publicarchive"

)

func main() { // Initialize the downloader downloader, err := publicarchive.NewDownloader(network.TestnetNetwork(), logging.Debug) if err != nil { fmt.Printf("Failed to create downloader: %v\n", err) os.Exit(1) }

// Start downloading
if err := downloader.Download(); err != nil {
	fmt.Printf("Download failed: %v\n", err)
	os.Exit(1)
}

// Specify the target directory for unpacking
targetDir := "./extracted_files"
if err := downloader.UnpackTo(targetDir); err != nil {
	fmt.Printf("Failed to unpack archive: %v\n", err)
	os.Exit(1)
}

fmt.Printf("Files successfully unpacked to %s\n", targetDir)

}

Documentation

Index

Constants

View Source
const (

	// public archive
	PChainArchiveTestnet = "https://luxd-public-shared-database.lux-test.network/testnet/p-chain/luxd/data-tar/latest.tar"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Downloader

type Downloader struct {
	// contains filtered or unexported fields
}

func NewDownloader

func NewDownloader(
	network network.Network,
	logger logging.Logger,
) (Downloader, error)

NewDownloader returns a new Downloader network: the network to download from ( testnet only). target: the path to download to logLevel: the log level

func (Downloader) CleanUp

func (d Downloader) CleanUp()

func (Downloader) Download

func (d Downloader) Download() error

func (Downloader) GetBytesComplete

func (d Downloader) GetBytesComplete() int64

GetCurrentProgress returns the current download progress

func (Downloader) GetDownloadSize

func (d Downloader) GetDownloadSize() int64

GetDownloadSize returns the size of the download

func (Downloader) GetFilePath

func (d Downloader) GetFilePath() (string, error)

func (Downloader) IsComplete

func (d Downloader) IsComplete() bool

IsComplete returns true if the download is complete

func (Downloader) IsEmpty

func (d Downloader) IsEmpty() bool

IsEmpty returns true if the Downloader is empty and not initialized

func (Downloader) UnpackTo

func (d Downloader) UnpackTo(targetDir string) error

type Getter

type Getter struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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