xfercommon

package
v0.7.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package xfercommon holds helpers for a file transfer that do not know which protocol is moving the bytes. FTP uses them. A later protocol can use the same ones.

Index

Constants

View Source
const (
	// MaxSize is the most a generated payload may be: 4 GiB.
	MaxSize = 4 << 30
	// MaxPath is the most bytes a remote path may be.
	MaxPath = 4096
	// MaxBody is the most a caller-supplied body may be.
	MaxBody = 64 << 20
)

Variables

This section is empty.

Functions

func CheckPath

func CheckPath(path string) error

CheckPath is CheckText for a remote path, and it also limits the length.

func CheckText

func CheckText(field, v string) error

CheckText refuses a CR, LF or NUL in v. The error names the field and does not include the value.

func FillReader

func FillReader(mode string, n int64) (io.Reader, error)

FillReader returns a reader of exactly n bytes. mode is random, zero or text. The same mode and n always produce the same bytes. The reader never holds those bytes all at once.

func HexDigest

func HexDigest(sum []byte) string

HexDigest is the hex encoding of sum, lowercase.

func NewHash

func NewHash() hash.Hash

NewHash returns a SHA-256 hash.

func ParseSize

func ParseSize(s string) (int64, error)

ParseSize reads a size such as 1024, 10KiB, 10MiB or 1GiB. The unit is 1024-based. A bare number is a count of bytes.

func ReplaceID

func ReplaceID(s, id string) string

ReplaceID replaces each {id} in s with id. Nothing else is substituted.

func ValidSHA256

func ValidSHA256(s string) bool

ValidSHA256 reports whether s is 64 hex characters.

Types

type CountingReader

type CountingReader struct {
	R io.Reader
	N int64
}

CountingReader counts the bytes read from r.

func (*CountingReader) Read

func (c *CountingReader) Read(p []byte) (int, error)

type CountingWriter

type CountingWriter struct {
	W io.Writer
	N int64
}

CountingWriter counts the bytes written to w.

func (*CountingWriter) Write

func (c *CountingWriter) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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