Documentation
¶
Overview ¶
ctx.go
Index ¶
- Constants
- Variables
- func ByteCountDecimal(b int64) string
- func ChunkRangesBytes(chunkRanges []int64, fileSize, defaultChunkSize int64) int64
- func ChunkRangesContain(chunkRanges []int64, position int64) bool
- func ChunkRangesCount(chunkRanges []int64, fileSize, defaultChunkSize int64) int
- func ChunkRangesToChunks(chunkRanges []int64) (chunks []int64)
- func Exists(name string) bool
- func FindOpenPorts(host string, portNumStart, numPorts int) (openPorts []int)
- func GenerateRandomPin() string
- func GetConfigDir(requireValidPath bool) (homedir string, err error)
- func GetInput(prompt string) (string, error)
- func GetInputContext(ctx context.Context, prompt string) (string, error)
- func GetLocalIPs() (ips []string, err error)
- func GetRandomName() string
- func HashFile(fname string, algorithm string, showProgress ...bool) (hash256 []byte, err error)
- func HashFileCtx(ctx context.Context, fname string, algorithm string, showProgress ...bool) ([]byte, error)
- func HighwayHashFile(fname string, doShowProgress bool) (hashHighway []byte, err error)
- func HighwayHashReader(sr *io.SectionReader, bar *progressbar.ProgressBar) ([]byte, error)
- func IMOHashFile(fname string) (hash []byte, err error)
- func IMOHashFileFull(fname string) (hash []byte, err error)
- func IMOHashReader(sr *io.SectionReader, bar *progressbar.ProgressBar) ([]byte, error)
- func IMOHashReaderFull(sr *io.SectionReader, bar *progressbar.ProgressBar) ([]byte, error)
- func IsLocalIP(ipaddress string) bool
- func LocalIP() string
- func MD5HashFile(fname string, doShowProgress bool) (hash256 []byte, err error)
- func MD5HashReader(sr *io.SectionReader, bar *progressbar.ProgressBar) ([]byte, error)
- func MarkFileForRemoval(fname string)
- func MissingChunks(fname string, fsize int64, chunkSize int) (chunkRanges []int64)
- func NewCtxFile(ctx context.Context, f *os.File) *ctxFile
- func NormalizeRelativePath(p string) string
- func PublicIP() (ip string, err error)
- func PublicIPContext(ctx context.Context) (ip string, err error)
- func RandomFileName() (fname string, err error)
- func RejectSymlinkPath(root, target string) error
- func RemoveMarkedFiles() (err error)
- func SHA256(s string) string
- func UnusedFilename(folder, name string) string
- func UnzipDirectory(destination string, source string) error
- func UnzipDirectoryContext(ctx context.Context, destination string, source string) error
- func UnzipDirectoryFromFileAtRootWithLimit(root *receivefs.Root, source *os.File, maxExtractedBytes int64) error
- func UnzipDirectoryFromFileAtRootWithLimitContext(ctx context.Context, root *receivefs.Root, source *os.File, ...) error
- func UnzipDirectoryWithLimit(destination string, source string, maxExtractedBytes int64) error
- func UnzipDirectoryWithLimitContext(ctx context.Context, destination string, source string, ...) error
- func ValidFileName(fname string) (err error)
- func XXHashFile(fname string, doShowProgress bool) (hash256 []byte, err error)
- func XXHashReader(sr *io.SectionReader, bar *progressbar.ProgressBar) ([]byte, error)
- func ZipDirectory(destination string, source string, ignoredPaths map[string]bool, ...) (err error)
- func ZipDirectoryContext(ctx context.Context, destination string, source string, ...) (err error)
- func ZipDirectoryWithExactExclusions(destination string, source string, ignoredPaths map[string]bool, ...) (err error)
- func ZipDirectoryWithExactExclusionsContext(ctx context.Context, destination string, source string, ...) (err error)
Constants ¶
const NbPinNumbers = 4
Variables ¶
var ErrUnzipSizeLimit = errors.New("zip extraction size limit exceeded")
ErrUnzipSizeLimit indicates that a zip archive would extract beyond the configured output-size limit.
Functions ¶
func ByteCountDecimal ¶
ByteCountDecimal converts bytes to human readable byte string
func ChunkRangesBytes ¶
ChunkRangesBytes returns the exact number of file bytes represented by ranges, including a possibly-short final chunk.
func ChunkRangesContain ¶
ChunkRangesContain reports whether the chunk at position is requested. An empty range list requests every chunk.
func ChunkRangesCount ¶
ChunkRangesCount returns the number of chunks represented by ranges. An empty range list means the whole file, matching the transfer protocol.
func ChunkRangesToChunks ¶
ChunkRangesToChunks converts chunk ranges to list
func FindOpenPorts ¶
func GenerateRandomPin ¶
func GenerateRandomPin() string
GenerateRandomPin returns a randomly generated pin with set length
func GetConfigDir ¶
Get or create home directory
func GetInput ¶
GetInput returns one line of input from stdin with a given prompt, with surrounding whitespace trimmed. On read error (e.g. closed or exhausted stdin) the returned string is empty, so callers that treat an empty answer as consent must check the error.
func GetInputContext ¶
GetInputContext returns one line of input from stdin, or the context error when the caller is canceled while waiting for input. The read runs in a goroutine because terminals and arbitrary pipes do not provide a portable context-aware read operation. A canceled CLI process exits without waiting for that goroutine.
func GetRandomName ¶
func GetRandomName() string
GetRandomName returns a random three-word croc code.
It retains its historical signature for callers outside croc. New code that needs to handle a random-source failure should call codephrase.Generate.
func HashFile ¶
HashFile returns the hash of a file or, in case of a symlink, the SHA256 hash of its target. Takes an argument to specify the algorithm to use.
func HashFileCtx ¶
func HashFileCtx(ctx context.Context, fname string, algorithm string, showProgress ...bool) ([]byte, error)
HashFileCtx returns the hash of a file with context cancellation support.
func HighwayHashFile ¶
HighwayHashFile returns highwayhash of a file
func HighwayHashReader ¶
func HighwayHashReader(sr *io.SectionReader, bar *progressbar.ProgressBar) ([]byte, error)
HighwayHashReader returns highwayhash for a SectionReader.
func IMOHashFile ¶
IMOHashFile returns imohash
func IMOHashFileFull ¶
IMOHashFileFull returns imohash of full file
func IMOHashReader ¶
func IMOHashReader(sr *io.SectionReader, bar *progressbar.ProgressBar) ([]byte, error)
IMOHashReader returns imohash for a SectionReader. Uses spinner progress bar for indeterminate progress.
func IMOHashReaderFull ¶
func IMOHashReaderFull(sr *io.SectionReader, bar *progressbar.ProgressBar) ([]byte, error)
IMOHashReaderFull returns full imohash (no sampling) for a SectionReader.
func MD5HashFile ¶
MD5HashFile returns MD5 hash
func MD5HashReader ¶
func MD5HashReader(sr *io.SectionReader, bar *progressbar.ProgressBar) ([]byte, error)
MD5HashReader returns MD5 hash for a SectionReader.
func MarkFileForRemoval ¶
func MarkFileForRemoval(fname string)
func MissingChunks ¶
MissingChunks returns the positions of missing chunks. If file doesn't exist, it returns an empty chunk list (all chunks). If the file size is not the same as requested, it returns an empty chunk list (all chunks).
func NewCtxFile ¶
NewCtxFile creates a new context-aware file wrapper.
func NormalizeRelativePath ¶
NormalizeRelativePath converts a path to a portable, clean relative-path representation suitable for exact comparisons.
func PublicIPContext ¶
PublicIPContext returns the public IPv4 address while allowing the caller to cancel the lookup.
func RandomFileName ¶
func RejectSymlinkPath ¶
RejectSymlinkPath rejects existing symlinks in target and its path components below root. This prevents writes through a pre-existing symlink from escaping the intended destination directory.
func RemoveMarkedFiles ¶
func RemoveMarkedFiles() (err error)
func UnusedFilename ¶
UnusedFilename returns a filename in folder that does not exist yet, appending " (1)", " (2)", etc. before the extension of name until an unused one is found.
func UnzipDirectory ¶
UnzipDirectory extracts source into destination. By default, extraction is limited to the archive's on-disk size. Croc-created zip archives use deflate without compression, so their extracted contents fit within this limit.
func UnzipDirectoryContext ¶
UnzipDirectoryContext is UnzipDirectory with cancellation support.
func UnzipDirectoryFromFileAtRootWithLimit ¶
func UnzipDirectoryFromFileAtRootWithLimit(root *receivefs.Root, source *os.File, maxExtractedBytes int64) error
UnzipDirectoryFromFileAtRootWithLimit extracts through the caller's already opened receive root, so a renamed or replaced working-directory path cannot switch the extraction destination after the transfer began.
func UnzipDirectoryFromFileAtRootWithLimitContext ¶
func UnzipDirectoryFromFileAtRootWithLimitContext(ctx context.Context, root *receivefs.Root, source *os.File, maxExtractedBytes int64) error
UnzipDirectoryFromFileAtRootWithLimitContext is UnzipDirectoryFromFileAtRootWithLimit with cancellation support.
func UnzipDirectoryWithLimit ¶
UnzipDirectoryWithLimit extracts source into destination while allowing at most maxExtractedBytes bytes of regular-file output in total.
func UnzipDirectoryWithLimitContext ¶
func UnzipDirectoryWithLimitContext(ctx context.Context, destination string, source string, maxExtractedBytes int64) error
UnzipDirectoryWithLimitContext is UnzipDirectoryWithLimit with cancellation support.
func ValidFileName ¶
ValidFileName checks if a filename is valid by making sure it has no invisible characters
func XXHashFile ¶
XXHashFile returns the xxhash of a file
func XXHashReader ¶
func XXHashReader(sr *io.SectionReader, bar *progressbar.ProgressBar) ([]byte, error)
XXHashReader returns xxhash for a SectionReader.
func ZipDirectory ¶
func ZipDirectory(destination string, source string, ignoredPaths map[string]bool, exclusions []string) (err error)
ZipDirectory writes the contents of source into a zip at destination. Files whose absolute path is present in ignoredPaths are skipped (used by the --git flag to honour .gitignore rules). Files whose zip path contains any string in exclusions (case-insensitive) are also skipped, mirroring the post-walk filter in cli.go for non-zip transfers.
func ZipDirectoryContext ¶
func ZipDirectoryContext(ctx context.Context, destination string, source string, ignoredPaths map[string]bool, exclusions []string) (err error)
ZipDirectoryContext is ZipDirectory with cancellation support.
func ZipDirectoryWithExactExclusions ¶
func ZipDirectoryWithExactExclusions(destination string, source string, ignoredPaths map[string]bool, exclusions, exactExclusions []string) (err error)
ZipDirectoryWithExactExclusions is ZipDirectory with support for exact paths relative to source. Legacy exclusions remain case-insensitive substring matches.
func ZipDirectoryWithExactExclusionsContext ¶
func ZipDirectoryWithExactExclusionsContext(ctx context.Context, destination string, source string, ignoredPaths map[string]bool, exclusions, exactExclusions []string) (err error)
ZipDirectoryWithExactExclusionsContext is ZipDirectoryWithExactExclusions with cancellation support. A canceled or otherwise failed operation removes the incomplete destination archive.
Types ¶
This section is empty.