github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/lfs/client.go (about) 1 // Copyright 2023 The GitBundle Inc. All rights reserved. 2 // Copyright 2017 The Gitea Authors. All rights reserved. 3 // Use of this source code is governed by a MIT-style 4 // license that can be found in the LICENSE file. 5 6 package lfs 7 8 import ( 9 "context" 10 "io" 11 "net/http" 12 "net/url" 13 ) 14 15 // DownloadCallback gets called for every requested LFS object to process its content 16 type DownloadCallback func(p Pointer, content io.ReadCloser, objectError error) error 17 18 // UploadCallback gets called for every requested LFS object to provide its content 19 type UploadCallback func(p Pointer, objectError error) (io.ReadCloser, error) 20 21 // Client is used to communicate with a LFS source 22 type Client interface { 23 BatchSize() int 24 Download(ctx context.Context, objects []Pointer, callback DownloadCallback) error 25 Upload(ctx context.Context, objects []Pointer, callback UploadCallback) error 26 } 27 28 // NewClient creates a LFS client 29 func NewClient(endpoint *url.URL, httpTransport *http.Transport) Client { 30 if endpoint.Scheme == "file" { 31 return newFilesystemClient(endpoint) 32 } 33 return newHTTPClient(endpoint, httpTransport) 34 }