Documentation
¶
Overview ¶
Package xfercommon holds helpers for a file transfer that do not know which protocol is moving the bytes. FTP and SFTP use them. This package has no FTP code and no SSH code.
Index ¶
- Constants
- func CheckPath(path string) error
- func CheckText(field, v string) error
- func Cut(s string, n int) string
- func FillReader(mode string, n int64) (io.Reader, error)
- func HashPayload(fill string, size int64, sizeSet bool, body []byte) string
- func HexDigest(sum []byte) string
- func NewHash() hash.Hash
- func ParseSize(s string) (int64, error)
- func ReadStream(r io.Reader, expect string, doHash bool) (int64, string, bool, error)
- func Refuse(prefix, mode, path string, allowWrites, allowAdmin, script bool) error
- func ReplaceID(s, id string) string
- func TextLeft(path string) string
- func ValidSHA256(s string) bool
- type CountingReader
- type CountingWriter
- type Entry
- type IDs
- type Job
- type Reply
- type Timing
Constants ¶
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 CheckText ¶
CheckText refuses a CR, LF or NUL in v. The error names the field and does not include the value.
func FillReader ¶
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 HashPayload ¶ added in v0.9.0
HashPayload is the SHA-256 hex of the bytes an upload would send.
func ParseSize ¶
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 ReadStream ¶ added in v0.9.0
ReadStream reads r to the end. It never keeps the whole stream. When expect is set, it looks for that text in the first 1 MiB. When hash is set, it returns the SHA-256 hex of the whole stream.
func Refuse ¶ added in v0.9.0
Refuse applies the write and delete safety rules. A nil error means the call may use the network.
func TextLeft ¶ added in v0.9.0
TextLeft is the reply text when a roundtrip file could not be deleted.
func ValidSHA256 ¶
ValidSHA256 reports whether s is 64 hex characters.
Types ¶
type CountingReader ¶
CountingReader counts the bytes read from r.
type CountingWriter ¶
CountingWriter counts the bytes written to w.
type IDs ¶ added in v0.9.0
type IDs struct {
// contains filtered or unexported fields
}
IDs makes a new {id} value for each call of one driver.
type Job ¶ added in v0.9.0
type Job struct {
Mode string
Path string
Size int64
SizeSet bool
Fill string
ExpectSize int64
ExpectSizeSet bool
ExpectSHA string
Expect string
Limit int
Hidden bool
}
Job is the work of one call. Connection options are not part of it.
func ParseJob ¶ added in v0.9.0
func ParseJob(prefix string, opts map[string]string, body []byte, isConn func(string) bool, listDefault string, rejectDashPath bool) (Job, error)
ParseJob reads the job options. prefix is the protocol name in errors. isConn reports a connection option, which this function ignores. listDefault is the path used when mode is list and path is empty. rejectDashPath refuses a list path that starts with "-".