Skip to content

Commit

Permalink
Populate bucket ID with file ID when local-only is enabled
Browse files Browse the repository at this point in the history
Since the B2 API requires the bucket ID to be used for single-chunk
downloads and the file ID to be used for multi-chunk uploads, both
should be populated with the same value (the file ID/name) when
local-only mode is enabled. This way the library can be used the same
with or without access to an actual B2 bucket.
  • Loading branch information
benbusby committed Mar 1, 2024
1 parent ba531a1 commit 1e7f0f6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions list_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func listLocalFiles(path string) (FileList, error) {
fileList = append(fileList, FileListItem{
FileName: name,
FileID: name,
BucketID: name,
ContentLength: int(stat.Size()),
})
}
Expand Down
3 changes: 2 additions & 1 deletion upload_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ func uploadLocalFile(

return File{
FileID: filename,
ContentLength: len(contents),
BucketID: filename,
FileName: filename,
ContentLength: len(contents),
}, nil
}
1 change: 1 addition & 0 deletions upload_large_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ func finishLargeLocalFile(id string, path string) (LargeFile, error) {
return LargeFile{
FileID: id,
FileName: id,
BucketID: id,
ContentLength: int(stat.Size()),
}, nil
}

0 comments on commit 1e7f0f6

Please sign in to comment.