fileutil

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package fileutil provides shared file-transfer utilities for invoke providers.

This package is intended to be used by provider implementations to avoid duplicating common patterns like progress reporting, context cancellation checking, and path traversal validation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPathTraversal

func CheckPathTraversal(root, target string) error

CheckPathTraversal validates that target is a child of root using local filesystem path conventions (filepath.Abs, os.PathSeparator). Returns an error if target escapes the root directory (ZipSlip protection).

func CheckRemotePathTraversal

func CheckRemotePathTraversal(root, target string) error

CheckRemotePathTraversal validates that target is a child of root using forward-slash path conventions (path.Clean, "/"). Use this for remote Unix-like paths where filepath operations would use the wrong separator on Windows hosts.

Types

type ContextReader

type ContextReader struct {
	Ctx    context.Context //nolint:containedctx
	Reader io.Reader
}

ContextReader wraps an io.Reader to check for context cancellation before each Read call. This allows long-running io.Copy operations to be interrupted by context cancellation.

func (*ContextReader) Read

func (cr *ContextReader) Read(p []byte) (int, error)

Read checks for context cancellation before delegating to the underlying reader.

type ProgressReader

type ProgressReader struct {
	io.Reader

	Total   int64
	Current int64
	Fn      invoke.ProgressFunc
}

ProgressReader wraps an io.Reader to report progress via an invoke.ProgressFunc. Total should be set to the known total size for percentage-based progress reporting, or 0 if unknown.

func (*ProgressReader) Read

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

Read reads from the underlying reader and reports progress.

Jump to

Keyboard shortcuts

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