Skip to content

Commit 820b3d8

Browse files
committedJun 3, 2015
Rename Add -> AddFile and AddFromReader -> Add
Juan argued for this rename because he expects the Reader-based case will be more common in a highly-networked world [1]. I'd rather have kept the old naming, because I expect some folks will think AddFile is only about leaf files (when it also handles directories and recursion via an *os.File file descriptor) [2]. But Juan still felt that the Reader-case deserved top billing [3], so go with his suggested naming. [1]: #1291 (comment) [2]: #1291 (comment) [3]: #1291 (comment)
1 parent e6b7dea commit 820b3d8

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed
 

‎add-api.md

+25-18
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,12 @@ I'd suggest moving `core/coreunix` to `core/unixfs` to match
6666
top bool
6767
) (nodeOut *dag.Node, err error)
6868

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:
7170
//
7271
// ctx: A Context for cancelling or timing out a recursive
7372
// addition.
7473
// 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.
7775
// preNodeCallBack: An optional hook for pre-DAG-node checks
7876
// (e.g. ignoring boring paths). Set to nil if you don't need
7977
// it.
@@ -83,29 +81,38 @@ I'd suggest moving `core/coreunix` to `core/unixfs` to match
8381
//
8482
// The returned values are:
8583
//
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.
8787
// err: Any errors serious enough to abort the addition.
8888
Add(
8989
ctx context.Context,
9090
node *core.IpfsNode,
91-
file *os.File,
91+
reader io.Reader,
9292
preNodeCallBack *PreNodeCallback,
9393
postNodeCallback *PostNodeCallback
9494
) (root *dag.Node, err error)
9595

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(
99101
ctx context.Context,
100102
node *core.IpfsNode,
101-
reader io.Reader,
103+
file *os.File,
102104
preNodeCallBack *PreNodeCallback,
103105
postNodeCallback *PostNodeCallback
104106
) (root *dag.Node, err error)
105107

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.
109116

110117
We need a way to get information about progress of a running addition
111118
back to other goroutines. Choices for this include [the channel
@@ -134,19 +141,19 @@ layout, and splitter, we pass each of those in explicitly:
134141
dagService dag.DAGService,
135142
layout _layout.Layout,
136143
splitter chunk.BlockSplitter,
137-
file *os.File,
144+
reader io.Reader,
138145
preNodeCallBack *PreNodeCallback,
139146
postNodeCallback *PostNodeCallback
140-
) (root *dag.Node, err error)
141-
AddFromReader(
147+
) (root *dag.Node, error)
148+
AddFile(
142149
ctx context.Context,
143150
dagService dag.DAGService,
144151
layout _layout.Layout,
145152
splitter chunk.BlockSplitter,
146-
reader io.Reader,
153+
file *os.File,
147154
preNodeCallBack *PreNodeCallback,
148155
postNodeCallback *PostNodeCallback
149-
) (root *dag.Node, error)
156+
) (root *dag.Node, err error)
150157

151158
We don't currently have a public `Layout` interface, but I think we
152159
should add one so folks can easily plug in alternative layout

0 commit comments

Comments
 (0)
Please sign in to comment.