transfer

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package transfer packs a folder for copying between machines and unpacks it at the other end, and picks the name a copy lands under. Both ends use it: the server for fs.upload and fs.download, the client for the same from this side.

An archive is gzipped tar with paths relative to the folder packed — no top folder of its own, since the receiving end decides what the copy is called. Unpacking takes the archive as untrusted: a sandbox is somebody else's machine, and what comes from it must not write outside the folder it was asked into.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FreeName

func FreeName(dir, name string) string

FreeName is name in dir, or when that is taken the first of "name 2", "name 3", … that is not, keeping the extension: a copy never lands on something already there unless asked to.

func FreeNameFS

func FreeNameFS(fsys FS, dir, name string) string

FreeNameFS is FreeName for a folder in fsys.

func Pack

func Pack(w io.Writer, src string) error

Pack writes the folder src to w as a gzipped tar: folders, files and symlinks (as links, never followed). Sockets, devices and the like are left out.

func PackFS

func PackFS(w io.Writer, fsys FS, src string) error

PackFS is Pack of a folder in fsys.

func SafeName

func SafeName(name string) string

SafeName makes a name from the other end safe to create here: its last path element, without control characters, and never empty, "." or "..".

func Unpack

func Unpack(r io.Reader, dest string, replace bool) error

Unpack extracts an archive Pack wrote into dest, which must exist. With replace, files already there are written over (folders are merged); without it, a name that is taken is an error. Nothing is written outside dest: a path that leaves it is refused, and so is going through a symlink, since one could lead anywhere.

func UnpackFS

func UnpackFS(r io.Reader, fsys FS, dest string, replace bool) error

UnpackFS is Unpack into a folder in fsys.

Types

type FS

type FS interface {
	Stat(name string) (fs.FileInfo, error)
	Lstat(name string) (fs.FileInfo, error)
	// ReadDir is a folder's entries as Lstat sees them, sorted by name.
	ReadDir(name string) ([]fs.FileInfo, error)
	// Open is a file to read. It must not wait on a fifo.
	Open(name string) (File, error)
	// Create makes a new file to write, refusing a name already taken.
	Create(name string, perm fs.FileMode) (File, error)
	Mkdir(name string, perm fs.FileMode) error
	Chmod(name string, mode fs.FileMode) error
	// Rename moves oldname to newname, replacing a file already there.
	Rename(oldname, newname string) error
	Remove(name string) error
	RemoveAll(name string) error
	Symlink(target, name string) error
	Readlink(name string) (string, error)
	// Home is where ~ is.
	Home() (string, error)
}

FS is the files a copy reads and writes: this machine's (Local), or a host's that a terminal is logged in to, through sftp. It is what the two have in common, with paths always slash-separated and absolute — conch runs on macOS and Linux, and sftp speaks POSIX paths.

var Local FS = localFS{}

Local is this machine's files.

type File

type File interface {
	io.Reader
	io.ReaderAt
	io.Writer
	io.WriterAt
	io.Closer
	Stat() (fs.FileInfo, error)
}

File is an open file of an FS.

func CreateTemp

func CreateTemp(fsys FS, dir, pattern string) (File, string, error)

CreateTemp makes a new file in dir named pattern with a random part in place of its "*", as os.CreateTemp does, and returns it with its path.

Jump to

Keyboard shortcuts

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