coreapi unixfs: docs on options
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Sep 20, 2018 at 23:44 UTC
9887a05e43906db7a0d9fc9ae05f9ed0f74083f1
3 files changed
+30
-3
core/coreapi/interface/options/unixfs.go
+28
-1
@@ -13,7 +13,7 @@ type Layout int
13
14
const (
15
BalancedLayout Layout = iota
16
- TrickleLeyout
16
+ TrickleLayout
17
)
18
19
type UnixfsAddSettings struct {
@@ -95,6 +95,8 @@ type unixfsOpts struct{}
95
96
var Unixfs unixfsOpts
97
98
+// CidVersion specifies which CID version to use. Defaults to 0 unless an option
99
+// that depends on CIDv1 is passed.
100
func (unixfsOpts) CidVersion(version int) UnixfsAddOption {
101
return func(settings *UnixfsAddSettings) error {
102
settings.CidVersion = version
@@ -102,6 +104,9 @@ func (unixfsOpts) CidVersion(version int) UnixfsAddOption {
104
}
105
}
106
107
+// Hash function to use. Implies CIDv1 if not set to sha2-256 (default).
108
+//
109
+// Table of functions is declared in https://github.com/multiformats/go-multihash/blob/master/multihash.go
110
func (unixfsOpts) Hash(mhtype uint64) UnixfsAddOption {
111
return func(settings *UnixfsAddSettings) error {
112
settings.MhType = mhtype
@@ -109,6 +114,8 @@ func (unixfsOpts) Hash(mhtype uint64) UnixfsAddOption {
114
}
115
}
116
117
+// RawLeaves specifies whether to use raw blocks for leaves (data nodes with no
118
+// links) instead of wrapping them with unixfs structures.
119
func (unixfsOpts) RawLeaves(enable bool) UnixfsAddOption {
120
return func(settings *UnixfsAddSettings) error {
121
settings.RawLeaves = enable
@@ -117,6 +124,11 @@ func (unixfsOpts) RawLeaves(enable bool) UnixfsAddOption {
124
}
125
}
126
127
+// InlineLimit sets the amount of bytes below which blocks will be encoded
128
+// directly into CID instead of being stored and addressed by it's hash
129
+//
130
+// Note that while there is no hard limit on the number of bytes here, it should
131
+// be kept at something reasonably low like 32b (default for 'ipfs add')
132
func (unixfsOpts) InlineLimit(limit int) UnixfsAddOption {
133
return func(settings *UnixfsAddSettings) error {
134
settings.InlineLimit = limit
@@ -124,6 +136,11 @@ func (unixfsOpts) InlineLimit(limit int) UnixfsAddOption {
136
}
137
}
138
139
+// Chunker specifies settings for the chunking algorithm to use.
140
+//
141
+// Default: size-262144, formats:
142
+// size-[bytes] - Simple chunker splitting data into blocks of n bytes
143
+// rabin-[min]-[avg]-[max] - Rabin chunker
144
func (unixfsOpts) Chunker(chunker string) UnixfsAddOption {
145
return func(settings *UnixfsAddSettings) error {
146
settings.Chunker = chunker
@@ -131,6 +148,10 @@ func (unixfsOpts) Chunker(chunker string) UnixfsAddOption {
148
}
149
}
150
151
+// Layout tells the adder how to balance data between leaves.
152
+// options.BalancedLayout is the default, it's optimized for static seekable
153
+// files.
154
+// options.TrickleLayout is optimized for streaming data,
155
func (unixfsOpts) Layout(layout Layout) UnixfsAddOption {
156
return func(settings *UnixfsAddSettings) error {
157
settings.Layout = layout
@@ -138,6 +159,7 @@ func (unixfsOpts) Layout(layout Layout) UnixfsAddOption {
159
}
160
}
161
162
+// Pin tells the adder to pin the file root recursively after adding
163
func (unixfsOpts) Pin(pin bool) UnixfsAddOption {
164
return func(settings *UnixfsAddSettings) error {
165
settings.Pin = pin
@@ -145,6 +167,8 @@ func (unixfsOpts) Pin(pin bool) UnixfsAddOption {
167
}
168
}
169
170
+// HashOnly will make the adder calculate data hash without storing it in the
171
+// blockstore or announcing it to the network
172
func (unixfsOpts) HashOnly(hashOnly bool) UnixfsAddOption {
173
return func(settings *UnixfsAddSettings) error {
174
settings.OnlyHash = hashOnly
@@ -152,6 +176,9 @@ func (unixfsOpts) HashOnly(hashOnly bool) UnixfsAddOption {
176
}
177
}
178
179
+// Local will add the data to blockstore without announcing it to the network
180
+//
181
+// Note that this doesn't prevent other nodes from getting this data
182
func (unixfsOpts) Local(local bool) UnixfsAddOption {
183
return func(settings *UnixfsAddSettings) error {
184
settings.Local = local
core/coreapi/unixfs.go
+1
-1
@@ -78,7 +78,7 @@ func (api *UnixfsAPI) Add(ctx context.Context, r io.ReadCloser, opts ...options.
78
switch settings.Layout {
79
case options.BalancedLayout:
80
// Default
81
- case options.TrickleLeyout:
81
+ case options.TrickleLayout:
82
fileAdder.Trickle = true
83
default:
84
return nil, fmt.Errorf("unknown layout: %d", settings.Layout)
core/coreapi/unixfs_test.go
+1
-1
@@ -202,7 +202,7 @@ func TestAdd(t *testing.T) {
202
name: "addChunksTrickle",
203
data: strings.Repeat("aoeuidhtns", 200),
204
path: "/ipfs/QmNNhDGttafX3M1wKWixGre6PrLFGjnoPEDXjBYpTv93HP",
205
- opts: []options.UnixfsAddOption{options.Unixfs.Chunker("size-4"), options.Unixfs.Layout(options.TrickleLeyout)},
205
+ opts: []options.UnixfsAddOption{options.Unixfs.Chunker("size-4"), options.Unixfs.Layout(options.TrickleLayout)},
206
},
207
// Local
208
{