-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransfer.go
More file actions
106 lines (88 loc) · 4.18 KB
/
transfer.go
File metadata and controls
106 lines (88 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package iron
import (
"context"
"io"
"github.com/kuleuven/iron/transfer"
)
// Upload uploads a local file to the iRODS server using parallel transfers.
// The local file refers to the local file system. The remote file refers to an iRODS path.
func (c *Client) Upload(ctx context.Context, local, remote string, options transfer.Options) error {
return c.runWorker(options, func(worker *transfer.Worker) {
worker.Upload(ctx, local, remote)
})
}
// UploadDir uploads a local directory to the iRODS server using parallel transfers.
// The local file refers to the local file system. The remote file refers to an iRODS path.
func (c *Client) UploadDir(ctx context.Context, local, remote string, options transfer.Options) error {
return c.runWorker(options, func(worker *transfer.Worker) {
worker.UploadDir(ctx, local, remote)
})
}
// FromReader streams an io.Reader to a remote file on the iRODS server using parallel transfers.
// The remote file refers to an iRODS path.
func (c *Client) FromReader(ctx context.Context, r io.Reader, remote string, appendToFile bool, options transfer.Options) error {
return c.runWorker(options, func(worker *transfer.Worker) {
worker.FromStream(ctx, remote, r, remote, appendToFile)
})
}
// Download downloads a remote file from the iRODS server using parallel transfers.
// The local file refers to the local file system. The remote file refers to an iRODS path.
func (c *Client) Download(ctx context.Context, local, remote string, options transfer.Options) error {
return c.runWorker(options, func(worker *transfer.Worker) {
worker.Download(ctx, local, remote)
})
}
// DownloadDir downloads a remote directory from the iRODS server using parallel transfers.
// The local file refers to the local file system. The remote file refers to an iRODS path.
func (c *Client) DownloadDir(ctx context.Context, local, remote string, options transfer.Options) error {
return c.runWorker(options, func(worker *transfer.Worker) {
worker.DownloadDir(ctx, local, remote)
})
}
// ToWriter streams a remote file from the iRODS server to an io.Writer using parallel transfers.
// The remote file refers to an iRODS path.
func (c *Client) ToWriter(ctx context.Context, w io.Writer, remote string, options transfer.Options) error {
return c.runWorker(options, func(worker *transfer.Worker) {
worker.ToStream(ctx, remote, w, remote)
})
}
// RemoveDir removes a remote directory from the iRODS server using client recursion.
// The remote file refers to an iRODS path.
func (c *Client) RemoveDir(ctx context.Context, remote string, options transfer.Options) error {
return c.runWorker(options, func(worker *transfer.Worker) {
worker.RemoveDir(ctx, remote)
})
}
// CopyDir copies a remote directory to another remote directory from the iRODS server using client recursion.
// The remote files refers to an iRODS path.
func (c *Client) CopyDir(ctx context.Context, remote1, remote2 string, options transfer.Options) error {
return c.runWorker(options, func(worker *transfer.Worker) {
worker.CopyDir(ctx, remote1, remote2)
})
}
// ComputeChecksums computes the checksums of a remote directory on the iRODS server using client recursion.
// The remote file refers to an iRODS path.
func (c *Client) ComputeChecksums(ctx context.Context, remote string, options transfer.Options) error {
return c.runWorker(options, func(worker *transfer.Worker) {
worker.ComputeChecksums(ctx, remote)
})
}
// runWorker creates a new pool with the given number of threads and
// creates a new transfer.Worker with it. The callback function is called
// with the created worker. The worker is started and the error returned
// is the error returned by the worker's Wait() function.
func (c *Client) runWorker(options transfer.Options, callback func(worker *transfer.Worker)) error {
pool, err := c.defaultPool.Pool(options.MaxThreads)
if err != nil {
return err
}
defer pool.Close()
worker := transfer.New(c.API, pool.API, options)
callback(worker)
return worker.Wait()
}
// Verify checks the checksum of a local file against the checksum of a remote file
func (c *Client) Verify(ctx context.Context, local, remote string) error {
_, _, err := transfer.VerifyLocalToRemote(c.API, nil)(ctx, local, remote, nil, nil)
return err
}