From: gitpubber <76197622+gitpubber@users.noreply.github.com> Date: Sun, 9 May 2021 09:34:41 +0000 (+0530) Subject: Allows one to use Custom PieceCompletion (#486) X-Git-Tag: v1.27.0 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=b8e1c9539907b177a7dac66c95304c0dbe91475f;p=btrtrc.git Allows one to use Custom PieceCompletion (#486) * Change ClientImpl to ClientImplCloser We cannot close underlying Boltdb PieceCompletion if it is not closable * Update file.go --- diff --git a/storage/file.go b/storage/file.go index a4c29015..1a273a34 100644 --- a/storage/file.go +++ b/storage/file.go @@ -36,7 +36,7 @@ func NewFile(baseDir string) ClientImplCloser { } func NewFileWithCompletion(baseDir string, completion PieceCompletion) *fileClientImpl { - return newFileWithCustomPathMakerAndCompletion(baseDir, nil, completion) + return NewFileWithCustomPathMakerAndCompletion(baseDir, nil, completion) } // File storage with data partitioned by infohash. @@ -48,10 +48,11 @@ func NewFileByInfoHash(baseDir string) ClientImplCloser { // responsible for sanitizing the info if it uses some part of it (for example sanitizing // info.Name). func NewFileWithCustomPathMaker(baseDir string, pathMaker func(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string) ClientImplCloser { - return newFileWithCustomPathMakerAndCompletion(baseDir, pathMaker, pieceCompletionForDir(baseDir)) + return NewFileWithCustomPathMakerAndCompletion(baseDir, pathMaker, pieceCompletionForDir(baseDir)) } -func newFileWithCustomPathMakerAndCompletion(baseDir string, pathMaker func(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string, completion PieceCompletion) *fileClientImpl { +// Allows passing custom PieceCompletion +func NewFileWithCustomPathMakerAndCompletion(baseDir string, pathMaker func(baseDir string, info *metainfo.Info, infoHash metainfo.Hash) string, completion PieceCompletion) *fileClientImpl { if pathMaker == nil { pathMaker = defaultPathMaker }