@cryptotaxi247 / kubo / commits / dfb14f397

coreapi unixfs: filestore opts

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@97fb3e4d819ee3ee511a719da6d1bef4695a2dad This commit was moved from ipfs/boxo@90e8604702cde52200882080a6a8b5b3e0818d13

Łukasz Magiera committed Oct 4, 2018 at 01:24 UTC dfb14f3974d44b6dd1670233c57d24552b9fbd83
1 file changed +35
core/coreiface/options/unixfs.go
+35
@@ -31,6 +31,8 @@ type UnixfsAddSettings struct {
31 Pin bool
32 OnlyHash bool
33 Local bool
34 + FsCache bool
35 + NoCopy bool
36
37 Wrap bool
38 Hidden bool
@@ -59,6 +61,8 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix,
61 Pin: false,
62 OnlyHash: false,
63 Local: false,
64 + FsCache: false,
65 + NoCopy: false,
66
67 Wrap: false,
68 Hidden: false,
@@ -76,6 +80,17 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix,
80 }
81 }
82
83 + // nocopy -> rawblocks
84 + if options.NoCopy && !options.RawLeaves {
85 + // fixed?
86 + if options.RawLeavesSet {
87 + return nil, cid.Prefix{}, fmt.Errorf("nocopy option requires '--raw-leaves' to be enabled as well")
88 + }
89 +
90 + // No, satisfy mandatory constraint.
91 + options.RawLeaves = true
92 + }
93 +
94 // (hash != "sha2-256") -> CIDv1
95 if options.MhType != mh.SHA2_256 {
96 switch options.CidVersion {
@@ -271,3 +286,23 @@ func (unixfsOpts) Progress(enable bool) UnixfsAddOption {
286 return nil
287 }
288 }
289 +
290 +// FsCache tells the adder to check the filestore for pre-existing blocks
291 +//
292 +// Experimental
293 +func (unixfsOpts) FsCache(enable bool) UnixfsAddOption {
294 + return func(settings *UnixfsAddSettings) error {
295 + settings.FsCache = enable
296 + return nil
297 + }
298 +}
299 +
300 +// NoCopy tells the adder to add the files using filestore. Implies RawLeaves.
301 +//
302 +// Experimental
303 +func (unixfsOpts) Nocopy(enable bool) UnixfsAddOption {
304 + return func(settings *UnixfsAddSettings) error {
305 + settings.NoCopy = enable
306 + return nil
307 + }
308 +}