xfer

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: AGPL-3.0 Imports: 6 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 xfer is what the transfers carried over a terminal's own byte stream (ZMODEM, trzsz) share: the stream as they see it, the files they carry, where those come from and where they go.

Index

Constants

This section is empty.

Variables

View Source
var ErrRefused = errors.New("xfer: cancelled by the other end")

ErrRefused is a transfer the other end refused or cancelled.

View Source
var ErrSkip = errors.New("xfer: skip this file")

ErrSkip, from Sink.Create, makes the transfer skip the file and go on with the next.

Functions

This section is empty.

Types

type Conn

type Conn interface {
	io.Reader
	io.Writer
	// SetReadDeadline makes a Read waiting past t return an error that
	// matches os.ErrDeadlineExceeded; the zero time waits for ever. What
	// is already waiting is read even past t, so a deadline in the past
	// polls. A Read after the session lost the shell returns io.EOF.
	SetReadDeadline(t time.Time) error
}

Conn is the shell's byte stream while a transfer has it: Read gives what the shell prints, from where the transfer was found on, Write sends to the shell as it is, never as typed (no newline translation, no local echo), and nothing typed reaches the shell meanwhile.

type File

type File struct {
	// Name is its path in the transfer, slash-separated: a base name, or
	// a path below a folder sent whole. It comes from the other end as
	// it is: whoever makes it a local name must check it.
	Name string
	// Size is its size in bytes, -1 when the other end did not say.
	Size int64
	// ModTime is when it last changed, zero when not said.
	ModTime time.Time
	// Mode holds its permission bits, 0 when not said.
	Mode fs.FileMode
	// Dir marks a folder: it has no content.
	Dir bool
}

File is a file or folder a transfer carries.

type Progress

type Progress func(f File, done int64)

Progress is told how a transfer goes: done is 0 when f starts, and grows as its bytes go through. It may be nil, and must not wait.

type Queue

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

Queue holds bytes one goroutine adds for another to read, as a Conn reads them: with read deadlines, what is waiting read even past one. It is how the shell's output reaches a transfer.

func NewQueue

func NewQueue(max int) *Queue

NewQueue returns a queue that holds up to max bytes before Add waits for them to be read; 0 holds any amount.

func (*Queue) Add

func (q *Queue) Add(p []byte) bool

Add queues p, waiting while the queue is full. It reports false, and takes nothing, once the queue is closed.

func (*Queue) Close

func (q *Queue) Close() []byte

Close ends the queue and returns what was left unread. Add then takes nothing, and Read returns io.EOF.

func (*Queue) Read

func (q *Queue) Read(p []byte) (int, error)

Read reads what is queued, waiting for some until the deadline; io.EOF once the queue is closed and empty.

func (*Queue) SetReadDeadline

func (q *Queue) SetReadDeadline(t time.Time) error

SetReadDeadline sets when a waiting Read gives up; zero waits for ever.

type Sink

type Sink interface {
	// Create starts receiving f, saved as local: its slash-separated
	// path, below where the files go, which may differ from f.Name for a
	// name already taken. For a folder it makes it and returns a nil
	// Writer. ErrSkip skips f; any other error ends the transfer.
	Create(f File) (local string, w Writer, err error)
}

Sink is where received files go.

type Source

type Source interface {
	// Files lists what is sent, in order, a folder before what is in it.
	Files() []File
	// Open opens the content of Files()[i], a file, which the transfer
	// closes.
	Open(i int) (io.ReadCloser, error)
}

Source is what is sent.

type Writer

type Writer interface {
	io.Writer
	// Commit keeps the file, once all of it came and checked out.
	Commit() error
	// Abort drops what was written; Commit or Abort is called once.
	Abort()
}

Writer takes a file's content as it is received.

Directories

Path Synopsis
Package xfertest has what tests of transfers over a terminal use: both ends of a byte stream, and files kept in memory.
Package xfertest has what tests of transfers over a terminal use: both ends of a byte stream, and files kept in memory.

Jump to

Keyboard shortcuts

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