From 922852ddad16d5b3f8880ce8ca7983021c5c7015 Mon Sep 17 00:00:00 2001 From: Eric Chen Date: Thu, 12 Dec 2019 22:16:03 -0800 Subject: [PATCH] Add repairs (hashes) to unixfs get options Also move metadata bool into the options --- go.sum | 7 ------- options/unixfs.go | 46 ++++++++++++++++++++++++++++++++-------------- unixfs.go | 5 ++--- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/go.sum b/go.sum index d62f986..c78b516 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,10 @@ github.com/AndreasBriese/bbloom v0.0.0-20180913140656-343706a395b7/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETFUpAzWW2ep1Y= github.com/Stebalien/go-bitfield v0.0.1/go.mod h1:GNjFpasyUVkHMsfEOk8EFLJ9syQ6SI+XWrX9Wf2XH0s= -github.com/TRON-US/go-btfs-chunker v0.2.0 h1:dp80UzRmUFzDDDt4nqo2STGVh5I4jDQJRYJYtRGulSo= -github.com/TRON-US/go-btfs-chunker v0.2.0/go.mod h1:6wFL7KgEumsn7R7IGFZZhOGIHxA/YkA4RdfR553M3Fk= github.com/TRON-US/go-btfs-chunker v0.2.2 h1:aiLDsiM3X2Yy2jVo3EQYYEVkw57SThOUPTs0Ja5yPeA= github.com/TRON-US/go-btfs-chunker v0.2.2/go.mod h1:Wj0oyybAWtu5lpcAc90QQ3bhJ14JRXD50PqxP25wmnI= github.com/TRON-US/go-btfs-files v0.1.1 h1:GuDIiWDM66bfhfxJy8+dBL4Cfbcp3iBp7pgHpKKCw8k= github.com/TRON-US/go-btfs-files v0.1.1/go.mod h1:tD2vOKLcLCDNMn9rrA27n2VbNpHdKewGzEguIFY+EJ0= -github.com/TRON-US/go-unixfs v0.4.1 h1:Vo1qIr8HT5D2GlfXaLG1lMrHq4plUyl1udIkCdVuF5U= -github.com/TRON-US/go-unixfs v0.4.1/go.mod h1:h/I7boDSgPi4Kw6qD/VJKQA62/+Lt+Zvb4nMRO57R1c= -github.com/TRON-US/go-unixfs v0.4.3-dev/go.mod h1:KJOb8DrNKJH9cdufqZba8ljdt3/vyo0KwfWNtwTzZbQ= github.com/TRON-US/go-unixfs v0.4.4 h1:EzTr7aHrB/vlAr4onYb/ENdsFt0NYNUGAefVD93r28w= github.com/TRON-US/go-unixfs v0.4.4/go.mod h1:VBRlISp23R6JoJQ2t+O/VkIswnPo9PBVCh5blMpN0GI= github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= @@ -116,8 +111,6 @@ github.com/ipfs/go-ipfs-exchange-interface v0.0.1 h1:LJXIo9W7CAmugqI+uofioIpRb6r github.com/ipfs/go-ipfs-exchange-interface v0.0.1/go.mod h1:c8MwfHjtQjPoDyiy9cFquVtVHkO9b9Ob3FG91qJnWCM= github.com/ipfs/go-ipfs-exchange-offline v0.0.1 h1:P56jYKZF7lDDOLx5SotVh5KFxoY6C81I1NSHW1FxGew= github.com/ipfs/go-ipfs-exchange-offline v0.0.1/go.mod h1:WhHSFCVYX36H/anEKQboAzpUws3x7UeEGkzQc3iNkM0= -github.com/ipfs/go-ipfs-files v0.0.3 h1:ME+QnC3uOyla1ciRPezDW0ynQYK2ikOh9OCKAEg4uUA= -github.com/ipfs/go-ipfs-files v0.0.3/go.mod h1:INEFm0LL2LWXBhNJ2PMIIb2w45hpXgPjNoE7yA8Y1d4= github.com/ipfs/go-ipfs-flags v0.0.1 h1:OH5cEkJYL0QgA+bvD55TNG9ud8HA2Nqaav47b2c/UJk= github.com/ipfs/go-ipfs-flags v0.0.1/go.mod h1:RnXBb9WV53GSfTrSDVK61NLTFKvWc60n+K9EgCDh+rA= github.com/ipfs/go-ipfs-posinfo v0.0.1 h1:Esoxj+1JgSjX0+ylc0hUmJCOv6V2vFoZiETLR6OtpRs= diff --git a/options/unixfs.go b/options/unixfs.go index 511fe51..5738c54 100644 --- a/options/unixfs.go +++ b/options/unixfs.go @@ -47,6 +47,8 @@ type UnixfsAddSettings struct { type UnixfsGetSettings struct { Decrypt bool PrivateKey string + Metadata bool + Repairs []cid.Cid } type UnixfsLsSettings struct { @@ -54,16 +56,16 @@ type UnixfsLsSettings struct { } type UnixfsAddMetaSettings struct { - Pin bool - Overwrite bool - Events chan<- interface{} - Silent bool + Pin bool + Overwrite bool + Events chan<- interface{} + Silent bool } type UnixfsRemoveMetaSettings struct { - Pin bool - Events chan<- interface{} - Silent bool + Pin bool + Events chan<- interface{} + Silent bool } type UnixfsAddOption func(*UnixfsAddSettings) error @@ -156,6 +158,8 @@ func UnixfsGetOptions(opts ...UnixfsGetOption) (*UnixfsGetSettings, error) { options := &UnixfsGetSettings{ Decrypt: false, PrivateKey: "", + Metadata: false, + Repairs: nil, } for _, opt := range opts { err := opt(options) @@ -183,9 +187,9 @@ func UnixfsLsOptions(opts ...UnixfsLsOption) (*UnixfsLsSettings, error) { func UnixfsAddMetaOptions(opts ...UnixfsAddMetaOption) (*UnixfsAddMetaSettings, error) { options := &UnixfsAddMetaSettings{ - Pin: false, - Events: nil, - Silent: false, + Pin: false, + Events: nil, + Silent: false, Overwrite: false, } @@ -201,9 +205,9 @@ func UnixfsAddMetaOptions(opts ...UnixfsAddMetaOption) (*UnixfsAddMetaSettings, func UnixfsRemoveMetaOptions(opts ...UnixfsRemoveMetaOption) (*UnixfsRemoveMetaSettings, error) { options := &UnixfsRemoveMetaSettings{ - Pin: false, - Events: nil, - Silent: false, + Pin: false, + Events: nil, + Silent: false, } for _, opt := range opts { @@ -251,6 +255,20 @@ func (unixfsOpts) PrivateKey(privateKey string) UnixfsGetOption { } } +func (unixfsOpts) Metadata(metadata bool) UnixfsGetOption { + return func(settings *UnixfsGetSettings) error { + settings.Metadata = metadata + return nil + } +} + +func (unixfsOpts) Repairs(repairs []cid.Cid) UnixfsGetOption { + return func(settings *UnixfsGetSettings) error { + settings.Repairs = repairs + return nil + } +} + type unixfsOpts struct{} var Unixfs unixfsOpts @@ -439,4 +457,4 @@ func (unixfsOpts) PinToRemove(pin bool) UnixfsRemoveMetaOption { settings.Pin = pin return nil } -} \ No newline at end of file +} diff --git a/unixfs.go b/unixfs.go index a076baa..85044f1 100644 --- a/unixfs.go +++ b/unixfs.go @@ -4,7 +4,7 @@ import ( "context" "github.com/TRON-US/interface-go-btfs-core/options" path "github.com/TRON-US/interface-go-btfs-core/path" - + "github.com/TRON-US/go-btfs-files" "github.com/ipfs/go-cid" ) @@ -71,8 +71,7 @@ type UnixfsAPI interface { // // Note that some implementations of this API may apply the specified context // to operations performed on the returned file. - // The bool parameter indicates whether token metadata should be returned. - Get(context.Context, path.Path, bool, ...options.UnixfsGetOption) (files.Node, error) + Get(context.Context, path.Path, ...options.UnixfsGetOption) (files.Node, error) // GetMetadata returns full metadata bytes within a UnixFS file referenced by path. // If metadata is not available, it returns an error.