Documentation ¶
Index ¶
- Variables
- func FtpEscapeBrackets(s string) string
- func FtpPwd(ftpaddr string, conn *ftp.ServerConn) (pwd string)
- func GetDavPath(davurl string) (dpath, fpath string, ok bool)
- func IsTypeIso(fpath string) bool
- func JoinFast(dir, base string) string
- func SftpPwd(ftpaddr string, client *sftp.Client) (pwd string)
- func SplitKey(fullpath string) (key, fpath string)
- func SplitUrl(urlpath string) (string, string)
- type Config
- type DavFileInfo
- type DavJoint
- func (j *DavJoint) Busy() bool
- func (j *DavJoint) Cleanup() error
- func (j *DavJoint) Close() (err error)
- func (j *DavJoint) Info(fpath string) (fi fs.FileInfo, err error)
- func (j *DavJoint) Make(base Joint, urladdr string) (err error)
- func (j *DavJoint) Open(fpath string) (file fs.File, err error)
- func (j *DavJoint) Read(b []byte) (n int, err error)
- func (j *DavJoint) ReadAt(b []byte, off int64) (n int, err error)
- func (j *DavJoint) ReadDir(n int) (ret []fs.DirEntry, err error)
- func (j *DavJoint) Seek(offset int64, whence int) (abs int64, err error)
- func (j *DavJoint) Stat() (fi fs.FileInfo, err error)
- type FtpFileInfo
- type FtpJoint
- func (j *FtpJoint) Busy() bool
- func (j *FtpJoint) Cleanup() error
- func (j *FtpJoint) Close() (err error)
- func (j *FtpJoint) Info(fpath string) (fi fs.FileInfo, err error)
- func (j *FtpJoint) Make(base Joint, urladdr string) (err error)
- func (j *FtpJoint) Open(fpath string) (file fs.File, err error)
- func (j *FtpJoint) Read(b []byte) (n int, err error)
- func (j *FtpJoint) ReadAt(b []byte, off int64) (n int, err error)
- func (j *FtpJoint) ReadDir(n int) (ret []fs.DirEntry, err error)
- func (j *FtpJoint) Seek(offset int64, whence int) (abs int64, err error)
- func (j *FtpJoint) Size() int64
- func (j *FtpJoint) Stat() (fi fs.FileInfo, err error)
- func (j *FtpJoint) Write(p []byte) (n int, err error)
- type IsoFileInfo
- type IsoJoint
- func (j *IsoJoint) Busy() bool
- func (j *IsoJoint) Cleanup() error
- func (j *IsoJoint) Close() error
- func (j *IsoJoint) Info(fpath string) (fi fs.FileInfo, err error)
- func (j *IsoJoint) Make(base Joint, isopath string) (err error)
- func (j *IsoJoint) Open(fpath string) (file fs.File, err error)
- func (j *IsoJoint) OpenFile(intpath string) (file *iso.File, err error)
- func (j *IsoJoint) ReadDir(n int) (ret []fs.DirEntry, err error)
- func (j *IsoJoint) Stat() (fs.FileInfo, error)
- type Joint
- type JointCache
- func (jc *JointCache) Close() (err error)
- func (jc *JointCache) Count() int
- func (jc *JointCache) Get() (jw JointWrap, err error)
- func (jc *JointCache) Has(j Joint) bool
- func (jc *JointCache) Key() string
- func (jc *JointCache) Open(fpath string) (f fs.File, err error)
- func (jc *JointCache) Pop() (jw JointWrap, ok bool)
- func (jc *JointCache) Put(j Joint)
- func (jc *JointCache) ReadDir(fpath string) (des []fs.DirEntry, err error)
- func (jc *JointCache) Stat(fpath string) (fi fs.FileInfo, err error)
- type JointPool
- func (jp *JointPool) Clear() error
- func (jp *JointPool) Close() error
- func (jp *JointPool) GetCache(key string) (jc *JointCache)
- func (jp *JointPool) GetJoint(key string) (j Joint, err error)
- func (jp *JointPool) Keys() []string
- func (jp *JointPool) Open(fullpath string) (f fs.File, err error)
- func (jp *JointPool) ReadDir(fullpath string) (ret []fs.DirEntry, err error)
- func (jp *JointPool) Stat(fullpath string) (fi fs.FileInfo, err error)
- type JointWrap
- type RFile
- type SftpFileStat
- type SftpJoint
- func (j *SftpJoint) Busy() bool
- func (j *SftpJoint) Cleanup() error
- func (j *SftpJoint) Close() (err error)
- func (j *SftpJoint) Info(fpath string) (fs.FileInfo, error)
- func (j *SftpJoint) Make(base Joint, urladdr string) (err error)
- func (j *SftpJoint) Open(fpath string) (file fs.File, err error)
- func (j *SftpJoint) ReadDir(n int) (ret []fs.DirEntry, err error)
- type SysJoint
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrFtpWhence = errors.New("invalid whence at FTP seeker") ErrFtpNegPos = errors.New("negative position at FTP seeker") )
Functions ¶
func FtpEscapeBrackets ¶
FtpEscapeBrackets escapes square brackets at FTP-path. FTP-server does not recognize path with square brackets as is to get a list of files, so such path should be escaped.
Example ¶
package main import ( "fmt" jnt "github.com/schwarzlichtbezirk/joint" ) func main() { fmt.Println(jnt.FtpEscapeBrackets("Music/Denney [2018]")) }
Output: Music/Denney [[]2018[]]
func FtpPwd ¶
func FtpPwd(ftpaddr string, conn *ftp.ServerConn) (pwd string)
FtpPwd return FTP current directory. It's used cache to avoid extra calls to FTP-server to get current directory for every call.
func GetDavPath ¶
GetDavPath searches true path to WebDAV resource by checking step-by-step elements of the path.
func IsTypeIso ¶ added in v0.2.0
IsTypeIso checks that endpoint-file in given path has ISO-extension.
func JoinFast ¶
JoinFast performs fast join of two path chunks.
Example ¶
package main import ( "fmt" jnt "github.com/schwarzlichtbezirk/joint" ) func main() { fmt.Println(jnt.JoinFast("any/path", "fox.txt")) fmt.Println(jnt.JoinFast("any/path/", "fox.txt")) fmt.Println(jnt.JoinFast("any", "/path/fox.txt")) fmt.Println(jnt.JoinFast("any/path/", "/fox.txt")) fmt.Println(jnt.JoinFast("/any/path", "fox.txt")) }
Output: any/path/fox.txt any/path/fox.txt any/path/fox.txt any/path/fox.txt /any/path/fox.txt
func SftpPwd ¶
SftpPwd return SFTP current directory. It's used cache to avoid extra calls to SFTP-server to get current directory for every call.
func SplitKey ¶ added in v0.2.0
SplitKey splits full path to joint key to establish link, and remained local path.
Example ¶
package main import ( "fmt" jnt "github.com/schwarzlichtbezirk/joint" ) func main() { var list = []string{ "some/path/fox.txt", "testdata/external.iso", "testdata/external.iso/fox.txt", "testdata/external.iso/disk/internal.iso/fox.txt", "ftp://music:x@192.168.1.1:21/Music", "ftp://music:x@192.168.1.1:21/testdata/external.iso/disk/internal.iso/docs/doc1.txt", } for _, s := range list { var key, fpath = jnt.SplitKey(s) fmt.Printf("key: '%s', path: '%s'\n", key, fpath) } }
Output: key: '', path: 'some/path/fox.txt' key: 'testdata/external.iso', path: '' key: 'testdata/external.iso', path: 'fox.txt' key: 'testdata/external.iso/disk/internal.iso', path: 'fox.txt' key: 'ftp://music:x@192.168.1.1:21', path: 'Music' key: 'ftp://music:x@192.168.1.1:21/testdata/external.iso/disk/internal.iso', path: 'docs/doc1.txt'
func SplitUrl ¶
SplitUrl splits URL to address string and to path as is.
Example ¶
package main import ( "fmt" jnt "github.com/schwarzlichtbezirk/joint" ) func main() { var list = []string{ "ftp://music:x@192.168.1.1:21/Music/DJ.m3u", "sftp://music:x@192.168.1.1:22/Video", "https://github.com/schwarzlichtbezirk/joint", "https://pkg.go.dev/github.com/schwarzlichtbezirk/joint", } for _, s := range list { var addr, fpath = jnt.SplitUrl(s) fmt.Printf("addr: %s, path: %s\n", addr, fpath) } }
Output: addr: ftp://music:x@192.168.1.1:21, path: Music/DJ.m3u addr: sftp://music:x@192.168.1.1:22, path: Video addr: https://github.com, path: schwarzlichtbezirk/joint addr: https://pkg.go.dev, path: github.com/schwarzlichtbezirk/joint
Types ¶
type Config ¶
type Config struct { // Timeout to establish connection to FTP-server. DialTimeout time.Duration `json:"dial-timeout" yaml:"dial-timeout" xml:"dial-timeout"` // Expiration duration to keep opened iso-disk structures in cache from last access to it. DiskCacheExpire time.Duration `json:"disk-cache-expire" yaml:"disk-cache-expire" xml:"disk-cache-expire"` }
type DavFileInfo ¶
type DavJoint ¶
type DavJoint struct { io.ReadCloser // contains filtered or unexported fields }
DavJoint keeps gowebdav.Client object. Key is URL to service, address + service route, i.e. https://user:pass@example.com/webdav/.
type FtpFileInfo ¶
FtpFileInfo encapsulates ftp.Entry structure and provides fs.FileInfo implementation.
func (FtpFileInfo) Sys ¶
func (fi FtpFileInfo) Sys() interface{}
fs.FileInfo implementation. Returns structure pointer itself.
type FtpJoint ¶
type FtpJoint struct { io.ReadCloser // contains filtered or unexported fields }
FtpJoint create connection to FTP-server, login with provided by given URL credentials, and gets a once current directory. Key is address of FTP-service, i.e. ftp://user:pass@example.com.
type IsoFileInfo ¶
func (IsoFileInfo) Name ¶
func (fi IsoFileInfo) Name() string
func (IsoFileInfo) Sys ¶
func (fi IsoFileInfo) Sys() interface{}
type IsoJoint ¶
type IsoJoint struct { Base Joint *iso.File *io.SectionReader // contains filtered or unexported fields }
IsoJoint opens file with ISO9660 disk and prepares disk-structure to access to nested files. Key is external path, to ISO9660-file disk image at local filesystem.
type Joint ¶
type Joint interface { Make(Joint, string) error // establish connection to file system provider Cleanup() error // close connection to file system provider Busy() bool // file is opened fs.FS // open file with local file path io.Closer // close local file fs.ReadDirFile // read directory pointed by local file path RFile }
Joint describes interface with joint to some file system provider.
type JointCache ¶
type JointCache struct {
// contains filtered or unexported fields
}
JointCache implements cache with opened joints to some file system resource.
func NewJointCache ¶
func NewJointCache(key string) *JointCache
func (*JointCache) Close ¶
func (jc *JointCache) Close() (err error)
Close performs close-call to all cached disk joints.
func (*JointCache) Count ¶
func (jc *JointCache) Count() int
Count is number of free joints in cache for one key path.
func (*JointCache) Get ¶
func (jc *JointCache) Get() (jw JointWrap, err error)
Get retrieves cached disk joint, or makes new one.
func (*JointCache) Has ¶
func (jc *JointCache) Has(j Joint) bool
Checks whether it is contained joint in cache.
func (*JointCache) Key ¶ added in v0.2.0
func (jc *JointCache) Key() string
func (*JointCache) Open ¶
func (jc *JointCache) Open(fpath string) (f fs.File, err error)
Open implements fs.FS interface, and returns file that can be casted to joint wrapper.
Example ¶
package main import ( "io" "log" "os" jnt "github.com/schwarzlichtbezirk/joint" ) func main() { var jc = jnt.NewJointCache("testdata/external.iso") defer jc.Close() var f, err = jc.Open("fox.txt") if err != nil { log.Fatal(err) } defer f.Close() io.Copy(os.Stdout, f) }
Output: The quick brown fox jumps over the lazy dog.
func (*JointCache) Pop ¶
func (jc *JointCache) Pop() (jw JointWrap, ok bool)
Pop retrieves cached disk joint, and returns ok if it has.
type JointPool ¶
type JointPool struct {
// contains filtered or unexported fields
}
JointPool is map with joint caches. Each key in map is path to file system resource, value - cached for this resource list of joints.
func NewJointPool ¶ added in v0.2.0
func NewJointPool() *JointPool
func (*JointPool) Clear ¶ added in v0.2.0
Clear is same as Close, and removes all entries in the map.
func (*JointPool) GetCache ¶ added in v0.2.0
func (jp *JointPool) GetCache(key string) (jc *JointCache)
GetCache returns cache from pool for given key path, or creates new one.
func (*JointPool) Open ¶ added in v0.2.0
Open opens file with given full path to this file, that can be located inside of nested ISO-images and/or on FTP, SFTP, WebDAV servers. Open implements fs.FS interface, and returns file that can be casted to joint wrapper.
Example ¶
package main import ( "io" "log" "os" jnt "github.com/schwarzlichtbezirk/joint" ) func main() { var jp = jnt.NewJointPool() // can be global declaration defer jp.Close() var j, err = jp.Open("testdata/external.iso/fox.txt") if err != nil { log.Fatal(err) } defer j.Close() io.Copy(os.Stdout, j) }
Output: The quick brown fox jumps over the lazy dog.
func (*JointPool) ReadDir ¶ added in v0.2.0
ReadDir returns directory files fs.DirEntry list pointed by given full path. ReadDir implements ReadDirFS interface.
Example ¶
package main import ( "fmt" "log" jnt "github.com/schwarzlichtbezirk/joint" ) func main() { var jp = jnt.NewJointPool() // can be global declaration defer jp.Close() var files, err = jp.ReadDir("testdata/external.iso/data") if err != nil { log.Fatal(err) } for _, de := range files { if de.IsDir() { fmt.Printf("dir: %s\n", de.Name()) } else { var fi, _ = de.Info() fmt.Printf("file: %s, %d bytes\n", de.Name(), fi.Size()) } } }
Output: dir: docs dir: empty file: lorem1.txt, 2747 bytes file: lorem2.txt, 2629 bytes file: lorem3.txt, 2714 bytes dir: доки file: рыба.txt, 1789 bytes
func (*JointPool) Stat ¶ added in v0.2.0
Stat returns fs.FileInfo of file pointed by given full path. Stat implements fs.StatFS interface.
Example ¶
package main import ( "fmt" "log" jnt "github.com/schwarzlichtbezirk/joint" ) func main() { var jp = jnt.NewJointPool() // can be global declaration defer jp.Close() var fi, err = jp.Stat("testdata/external.iso/fox.txt") if err != nil { log.Fatal(err) } fmt.Printf("name: %s, size: %d\n", fi.Name(), fi.Size()) }
Output: name: fox.txt, size: 44
type JointWrap ¶
type JointWrap struct { Joint // contains filtered or unexported fields }
JointWrap helps to return joint into cache after Close-call.
func (JointWrap) Cleanup ¶ added in v0.2.0
Cleanup ejects itself from binded cache, and make inner Cleanup-call. This function is for special cases only.
func (JointWrap) GetCache ¶ added in v0.2.0
func (jw JointWrap) GetCache() *JointCache
GetCache returns binded cache.
type SftpFileStat ¶
type SftpJoint ¶
SftpJoint create SSH-connection to SFTP-server, login with provided by given URL credentials, and gets a once current directory. Key is address of SFTP-service, i.e. sftp://user:pass@example.com.