From e6b7dea8dca12aa90178ffcb318d1e3541a32eff Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 3 Jun 2015 12:57:08 -0700 Subject: [PATCH] Revert "Replace single callbacks with slices of function references" This reverts commit d617dfbb314fd389015a70f07a54565e2359c6d0. On Wed, Jun 03, 2015 at 01:54:03AM -0700, Juan Batiz-Benet wrote [1]: > > it's probably worth passing an array of NodeCallback (and > > PreNodeCallback) references to the adders > > i think this is way overkill. one can chain the calls with one > function themselves. you might even provide a utility function that > turns N callbacks into one which applies them sequentially, but this > function should just accept one callback. That's a much cleaner approach, so we're going back to the non-slice callbacks. [1]: https://github.com/ipfs/go-ipfs/issues/1291#issuecomment-108252302 --- add-api.md | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/add-api.md b/add-api.md index 6f59874a3c8..f9c82deba7f 100644 --- a/add-api.md +++ b/add-api.md @@ -74,21 +74,12 @@ I'd suggest moving `core/coreunix` to `core/unixfs` to match // node: And IPFS node for storing newly-created DAG nodes. // file: An open file pointing at the root of the filesystem to be // added. - // preNodeCallBacks: An optional slice of hooks for pre-DAG-node - // checks (e.g. ignoring boring paths). Before adding a path, - // Add will iterate through the preNodeCallbacks and ignore - // the path (and stop further preNodeCallbacks iteration) if - // any of the callbacks set ignore to true. Set to nil if you - // don't need it. - // postNodeCallBacks: An optional slice of hooks for - // post-DAG-node processing (e.g. altering or wrapping the - // newly-created nodes). After creating a node, Add will - // iterate through the postNodeCallbacks, passing nodeOut from - // earlier callbacks in as nodeIn to the next callback. For - // example, if Add internally creates node1, the first - // callback will get node1 as nodeIn. If that callback - // returns node2 (possibly nil), the second callback will get - // node2 as nodeIn. Set to nil if you don't need it. + // preNodeCallBack: An optional hook for pre-DAG-node checks + // (e.g. ignoring boring paths). Set to nil if you don't need + // it. + // postNodeCallBack: An optional hook for post-DAG-node + // processing (e.g. altering or wrapping the newly-created + // nodes). Set to nil if you don't need it. // // The returned values are: // @@ -98,8 +89,8 @@ I'd suggest moving `core/coreunix` to `core/unixfs` to match ctx context.Context, node *core.IpfsNode, file *os.File, - preNodeCallBacks []*PreNodeCallback, - postNodeCallbacks []*PostNodeCallback + preNodeCallBack *PreNodeCallback, + postNodeCallback *PostNodeCallback ) (root *dag.Node, err error) // AddFromReader adds a file from an io.Reader. It is otherwise @@ -108,8 +99,8 @@ I'd suggest moving `core/coreunix` to `core/unixfs` to match ctx context.Context, node *core.IpfsNode, reader io.Reader, - preNodeCallBacks []*PreNodeCallback, - postNodeCallbacks []*PostNodeCallback + preNodeCallBack *PreNodeCallback, + postNodeCallback *PostNodeCallback ) (root *dag.Node, err error) Most additions will be recursive and load data from a [*File][File] @@ -144,8 +135,8 @@ layout, and splitter, we pass each of those in explicitly: layout _layout.Layout, splitter chunk.BlockSplitter, file *os.File, - preNodeCallBacks []*PreNodeCallback, - postNodeCallbacks []*PostNodeCallback + preNodeCallBack *PreNodeCallback, + postNodeCallback *PostNodeCallback ) (root *dag.Node, err error) AddFromReader( ctx context.Context, @@ -153,8 +144,8 @@ layout, and splitter, we pass each of those in explicitly: layout _layout.Layout, splitter chunk.BlockSplitter, reader io.Reader, - preNodeCallBacks []*PreNodeCallback, - postNodeCallbacks []*PostNodeCallback + preNodeCallBack *PreNodeCallback, + postNodeCallback *PostNodeCallback ) (root *dag.Node, error) We don't currently have a public `Layout` interface, but I think we