@@ -66,14 +66,12 @@ I'd suggest moving `core/coreunix` to `core/unixfs` to match
66
66
top bool
67
67
) (nodeOut *dag.Node, err error)
68
68
69
- // Add recursively adds files from a File type, which can point to
70
- // either a directory or a file. The arguments are:
69
+ // Add adds a single file from an io.Reader. The arguments are:
71
70
//
72
71
// ctx: A Context for cancelling or timing out a recursive
73
72
// addition.
74
73
// node: And IPFS node for storing newly-created DAG nodes.
75
- // file: An open file pointing at the root of the filesystem to be
76
- // added.
74
+ // reader: A Reader from which the file contents are read.
77
75
// preNodeCallBack: An optional hook for pre-DAG-node checks
78
76
// (e.g. ignoring boring paths). Set to nil if you don't need
79
77
// it.
@@ -83,29 +81,38 @@ I'd suggest moving `core/coreunix` to `core/unixfs` to match
83
81
//
84
82
// The returned values are:
85
83
//
86
- // root: The root of the just-added DAG.
84
+ // root: The root of the just-added DAG. Even though we're only
85
+ // adding a single file, layout and chunking choices may lead
86
+ // to the creation of several Merkle objects.
87
87
// err: Any errors serious enough to abort the addition.
88
88
Add(
89
89
ctx context.Context,
90
90
node *core.IpfsNode,
91
- file *os.File ,
91
+ reader io.Reader ,
92
92
preNodeCallBack *PreNodeCallback,
93
93
postNodeCallback *PostNodeCallback
94
94
) (root *dag.Node, err error)
95
95
96
- // AddFromReader adds a file from an io.Reader. It is otherwise
97
- // identical to Add(), but is obviously not recursive.
98
- AddFromReader(
96
+ // AddFile recursively adds files from a File type, which can
97
+ // point to either a directory or a file. The signature matches
98
+ // Add, except that the 'reader' io.Reader is replaced by the
99
+ // 'file' *os.File.
100
+ AddFile(
99
101
ctx context.Context,
100
102
node *core.IpfsNode,
101
- reader io.Reader ,
103
+ file *os.File ,
102
104
preNodeCallBack *PreNodeCallback,
103
105
postNodeCallback *PostNodeCallback
104
106
) (root *dag.Node, err error)
105
107
106
- Most additions will be recursive and load data from a [ * File] [ File ]
107
- (which can be a directory or a file). Alternatively, the
108
- ` *FromReader ` variants accept a [ Reader] [ 2 ] .
108
+ Single file additions can use a [ Reader] [ ] , but filesystem-based
109
+ additions may find the recursive, [ * File] [ File ] -based AddFile more
110
+ convenient, because:
111
+
112
+ 1 . It handles directory recursion internally, and
113
+ 2 . It allows access to local metadata (access mode, ownership, …) and
114
+ root-relative filenames for use by the pre- and post-node
115
+ callbacks.
109
116
110
117
We need a way to get information about progress of a running addition
111
118
back to other goroutines. Choices for this include [ the channel
@@ -134,19 +141,19 @@ layout, and splitter, we pass each of those in explicitly:
134
141
dagService dag.DAGService,
135
142
layout _layout.Layout,
136
143
splitter chunk.BlockSplitter,
137
- file *os.File ,
144
+ reader io.Reader ,
138
145
preNodeCallBack *PreNodeCallback,
139
146
postNodeCallback *PostNodeCallback
140
- ) (root *dag.Node, err error)
141
- AddFromReader (
147
+ ) (root *dag.Node, error)
148
+ AddFile (
142
149
ctx context.Context,
143
150
dagService dag.DAGService,
144
151
layout _layout.Layout,
145
152
splitter chunk.BlockSplitter,
146
- reader io.Reader ,
153
+ file *os.File ,
147
154
preNodeCallBack *PreNodeCallback,
148
155
postNodeCallback *PostNodeCallback
149
- ) (root *dag.Node, error)
156
+ ) (root *dag.Node, err error)
150
157
151
158
We don't currently have a public ` Layout ` interface, but I think we
152
159
should add one so folks can easily plug in alternative layout
0 commit comments