Skip to content

Commit ee4c43f

Browse files
committed
Added parameter to control upload range size
1 parent 6d8d405 commit ee4c43f

File tree

6 files changed

+22
-14
lines changed

6 files changed

+22
-14
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.6.2
1+
v0.7.0

main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import (
1212
)
1313

1414
type Flags struct {
15-
ConfigPath string
16-
Verbose bool
17-
Quiet bool
15+
ConfigPath string
16+
Verbose bool
17+
Quiet bool
18+
UploadSessionRangeSize int
1819
}
1920

2021
var (
@@ -40,6 +41,7 @@ func printHelp() {
4041

4142
func prepareFlags() {
4243
flag.StringVar(&AppFlags.ConfigPath, "c", "", "path to config.json")
44+
flag.IntVar(&AppFlags.UploadSessionRangeSize, "u", 320*30, "upload range size in KB (multiple of 320 KB)")
4345
flag.BoolVar(&AppFlags.Quiet, "q", false, "output errors only")
4446
flag.BoolVar(&AppFlags.Verbose, "v", false, "verbose output")
4547
flag.Parse()
@@ -127,6 +129,7 @@ func main() {
127129
client = sdk.CreateClient(conf)
128130
client.UseTransferSignals = true
129131
client.Verbose = AppFlags.Verbose
132+
client.UploadSessionRangeSize = AppFlags.UploadSessionRangeSize
130133
if cmdDef.InitSecretStore {
131134
logVerbose("Reading secret store...")
132135
if client.ShouldRenewAccessToken() {

sdk/client.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type transferProgress func(int64)
2222
type Client struct {
2323
Config *Config
2424
Verbose bool
25+
UploadSessionRangeSize int
2526
UseTransferSignals bool
2627
ChannelTransferStart chan fs.FileInfo
2728
ChannelTransferProgress chan int64
@@ -32,9 +33,10 @@ type HTTPRequestParams map[string]string
3233

3334
func CreateClient(conf *Config) *Client {
3435
client := &Client{
35-
Config: conf,
36-
Verbose: false,
37-
UseTransferSignals: false,
36+
Config: conf,
37+
UploadSessionRangeSize: 320 * 30,
38+
Verbose: false,
39+
UseTransferSignals: false,
3840
}
3941
client.ResetChannels()
4042
return client

sdk/integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func TestUploadDownloadSmall(t *testing.T) {
9292
func TestUploadDownloadLarge(t *testing.T) {
9393
dirName := "/test-" + uuid.New().String()
9494
fileName := uuid.New().String() + ".dat"
95-
fileSizeKB := (UploadSessionFileSizeLimit / 1000 * 2) + 10
95+
fileSizeKB := (UploadSessionFileSizeLimit / 1024 * 2) + 10
9696
err := createRandomFile("/tmp/"+fileName, fileSizeKB)
9797
checkTestBool(t, true, err == nil)
9898
defer os.Remove("/tmp/" + fileName)

sdk/upload.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import (
1010
)
1111

1212
var (
13-
UploadSessionFileSizeLimit int = 4 * 1000 * 1000 // 4 MB
14-
UploadSessionMultiple int = 320 * 1024 // 320 KB
15-
UploadSessionRangeSize int = UploadSessionMultiple * 10
13+
UploadSessionFileSizeLimit int = 10 * 1024 * 1024 // 10 MB
14+
UploadSessionMultiple int = 320 * 1024 // 320 KB
1615
)
1716

1817
type UploadSessionResponse struct {
@@ -63,7 +62,11 @@ func (client *Client) Upload(localFilePath, targetFolder string) error {
6362
}
6463

6564
func (client *Client) uploadToSession(uploadUrl, mimeType, localFilePath string, fileSize int64) error {
66-
data := make([]byte, UploadSessionRangeSize)
65+
if (client.UploadSessionRangeSize <= 0) || (client.UploadSessionRangeSize%320 != 0) {
66+
return errors.New("upload session range size must be a multiple of 320")
67+
}
68+
rangeSizeBytes := client.UploadSessionRangeSize * 1024
69+
data := make([]byte, rangeSizeBytes)
6770
f, err := os.Open(localFilePath)
6871
if err != nil {
6972
return err
@@ -73,7 +76,7 @@ func (client *Client) uploadToSession(uploadUrl, mimeType, localFilePath string,
7376
n := 0
7477
for offset < fileSize {
7578
n, _ = f.ReadAt(data, offset)
76-
if n < UploadSessionRangeSize {
79+
if n < rangeSizeBytes {
7780
data = append([]byte(nil), data[:n]...)
7881
}
7982
progress := func(b int64) {

version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package main
22

3-
var AppVersion = "v0.6.2"
3+
var AppVersion = "v0.7.0"

0 commit comments

Comments
 (0)