github.com/0chain/gosdk@v1.17.11/zboxcore/sdk/downloader_option.go (about)

     1  package sdk
     2  
     3  import "github.com/0chain/gosdk/core/sys"
     4  
     5  const DefaultBlocksPerMarker int = 100
     6  
     7  // DownloadOption set download option
     8  type DownloadOption func(do *DownloadOptions)
     9  
    10  // WithVerifyDownload set verify download option for the download request options.
    11  // If true, the response will contain proof of the download to be verified at the client side.
    12  // 		- shouldVerify: true to verify download, false to not verify download.
    13  func WithVerifyDownload(shouldVerify bool) DownloadOption {
    14  	return func(do *DownloadOptions) {
    15  		do.verifyDownload = shouldVerify
    16  	}
    17  }
    18  
    19  // WithAllocation set allocation object of the download option
    20  func WithAllocation(obj *Allocation) DownloadOption {
    21  	return func(do *DownloadOptions) {
    22  		do.allocationObj = obj
    23  	}
    24  }
    25  
    26  // WithBlocks set block range for the download request options.
    27  // 		- start: start block number
    28  // 		- end: end block number
    29  // 		- blocksPerMarker: number of blocks to download
    30  func WithBlocks(start, end int64, blocksPerMarker int) DownloadOption {
    31  	return func(do *DownloadOptions) {
    32  		if start > 0 && end > 0 && end >= start {
    33  			do.isBlockDownload = true
    34  
    35  			do.startBlock = start
    36  			do.endBlock = end
    37  		}
    38  
    39  		do.blocksPerMarker = blocksPerMarker
    40  		if do.blocksPerMarker < 1 {
    41  			do.blocksPerMarker = DefaultBlocksPerMarker
    42  		}
    43  
    44  		SetNumBlockDownloads(do.blocksPerMarker)
    45  	}
    46  }
    47  
    48  // WithOnlyThumbnail set thumbnail download option which makes the request download only the thumbnail.
    49  // 		- thumbnail: true to download only thumbnail, false to download the file.
    50  func WithOnlyThumbnail(thumbnail bool) DownloadOption {
    51  	return func(do *DownloadOptions) {
    52  		do.isThumbnailDownload = thumbnail
    53  	}
    54  }
    55  
    56  // WithAuthTicket set auth ticket and lookup hash for the download request options
    57  // This is used to download shared files.
    58  // 		- authTicket: is the ticket that is generated by the owner of the file to access their shared file.
    59  // 		- lookupHash: is an augmented hash of the allocation ID and the path of the file, used to locate the file.
    60  func WithAuthticket(authTicket, lookupHash string) DownloadOption {
    61  	return func(do *DownloadOptions) {
    62  		if len(authTicket) > 0 {
    63  			do.isViewer = true
    64  			do.authTicket = authTicket
    65  			do.lookupHash = lookupHash
    66  		}
    67  	}
    68  }
    69  
    70  // WithFileHandler set file handler for the download request options
    71  func WithFileHandler(fileHandler sys.File) DownloadOption {
    72  	return func(do *DownloadOptions) {
    73  		do.fileHandler = fileHandler
    74  		do.isFileHandlerDownload = true
    75  	}
    76  }