files2.0: refactored helpers

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
Łukasz Magiera 2018-12-13 22:41:21 +01:00
parent ff42aa50d0
commit eed806a58b
13 changed files with 83 additions and 86 deletions

View File

@ -16,10 +16,10 @@ import (
namesys "github.com/ipfs/go-ipfs/namesys"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
"gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
"gx/ipfs/QmYyzmMnhNTtoXx5ttgUaRdHHckYnQWjPL98hgLAR2QLDD/go-ipfs-config"
"gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
"gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files"
)
const (
@ -90,12 +90,12 @@ environment variable:
if !it.Next() && it.Err() != nil {
return it.Err()
}
if files.FileFrom(it) == nil {
if files.FileFromEntry(it) == nil {
return fmt.Errorf("expected a regular file")
}
conf = &config.Config{}
if err := json.NewDecoder(files.FileFrom(it)).Decode(conf); err != nil {
if err := json.NewDecoder(files.FileFromEntry(it)).Decode(conf); err != nil {
return err
}
}

View File

@ -11,9 +11,9 @@ import (
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files"
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
)
@ -158,7 +158,7 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
if !it.Next() && it.Err() != nil {
return it.Err()
}
if files.FileFrom(it) == nil {
if files.FileFromEntry(it) == nil {
return fmt.Errorf("expected a regular file")
}
@ -182,7 +182,7 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
}
}
p, err := api.Block().Put(req.Context, files.FileFrom(it), options.Block.Hash(mhtval, mhlen), options.Block.Format(format))
p, err := api.Block().Put(req.Context, files.FileFromEntry(it), options.Block.Hash(mhtval, mhlen), options.Block.Format(format))
if err != nil {
return err
}

View File

@ -15,10 +15,10 @@ import (
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
"gx/ipfs/QmP2i47tnU23ijdshrZtuvrSkQPtf9HhsMb9fwGVe8owj2/jsondiff"
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
config "gx/ipfs/QmYyzmMnhNTtoXx5ttgUaRdHHckYnQWjPL98hgLAR2QLDD/go-ipfs-config"
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files"
)
// ConfigUpdateOutput is config profile apply command's output
@ -285,10 +285,10 @@ can't be undone.
if !it.Next() && it.Err() != nil {
return it.Err()
}
if files.FileFrom(it) == nil {
if files.FileFromEntry(it) == nil {
return fmt.Errorf("expected a regular file")
}
file := files.FileFrom(it)
file := files.FileFromEntry(it)
defer file.Close()
return replaceConfig(r, file)

View File

@ -10,11 +10,11 @@ import (
"github.com/ipfs/go-ipfs/pin"
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
path "gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path"
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files"
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
)
@ -95,10 +95,10 @@ into an object of the specified format.
it := req.Files.Entries()
for it.Next() {
if files.FileFrom(it) == nil {
if files.FileFromEntry(it) == nil {
return fmt.Errorf("expected a regular file")
}
nds, err := coredag.ParseInputs(ienc, format, files.FileFrom(it), mhType, -1)
nds, err := coredag.ParseInputs(ienc, format, files.FileFromEntry(it), mhType, -1)
if err != nil {
return err
}

View File

@ -18,6 +18,7 @@ import (
bservice "gx/ipfs/QmPoh3SrQzFBWtdGK6qmHDV4EanKR6kYPj4DD3J2NLoEmZ/go-blockservice"
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
mfs "gx/ipfs/QmU3iDRUrxyTYdV2j5MuWLFvP1k7w98vD66PLnNChgvUmZ/go-mfs"
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
offline "gx/ipfs/QmYZwey1thDTynSrvd6qQkX24UpTka6TFhQ2v569UpoqxD/go-ipfs-exchange-offline"
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
ft "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs"
@ -25,7 +26,6 @@ import (
logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log"
dag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files"
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
)
@ -774,11 +774,11 @@ stat' on the file or any of its ancestors.
if !it.Next() && it.Err() != nil {
return it.Err()
}
if files.FileFrom(it) == nil {
if files.FileFromEntry(it) == nil {
return fmt.Errorf("expected a regular file")
}
var r io.Reader = files.FileFrom(it)
var r io.Reader = files.FileFromEntry(it)
if countfound {
r = io.LimitReader(r, int64(count))
}

View File

@ -13,11 +13,11 @@ import (
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
dag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files"
)
type Node struct {
@ -396,7 +396,7 @@ And then run:
if !it.Next() && it.Err() != nil {
return it.Err()
}
if files.FileFrom(it) == nil {
if files.FileFromEntry(it) == nil {
return fmt.Errorf("expected a regular file")
}
@ -415,7 +415,7 @@ And then run:
return err
}
p, err := api.Object().Put(req.Context, files.FileFrom(it),
p, err := api.Object().Put(req.Context, files.FileFromEntry(it),
options.Object.DataType(datafieldenc),
options.Object.InputEnc(inputenc),
options.Object.Pin(dopin))

View File

@ -8,9 +8,9 @@ import (
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
"gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
"gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
"gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files"
)
var ObjectPatchCmd = &cmds.Command{
@ -65,11 +65,11 @@ the limit will not be respected by the network.
if !it.Next() && it.Err() != nil {
return it.Err()
}
if files.FileFrom(it) == nil {
if files.FileFromEntry(it) == nil {
return fmt.Errorf("expected a regular file")
}
p, err := api.Object().AppendData(req.Context, root, files.FileFrom(it))
p, err := api.Object().AppendData(req.Context, root, files.FileFromEntry(it))
if err != nil {
return err
}
@ -115,11 +115,11 @@ Example:
if !it.Next() && it.Err() != nil {
return it.Err()
}
if files.FileFrom(it) == nil {
if files.FileFromEntry(it) == nil {
return fmt.Errorf("expected a regular file")
}
p, err := api.Object().SetData(req.Context, root, files.FileFrom(it))
p, err := api.Object().SetData(req.Context, root, files.FileFromEntry(it))
if err != nil {
return err
}

View File

@ -9,11 +9,11 @@ import (
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
tar "github.com/ipfs/go-ipfs/tar"
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
"gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path"
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
dag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files"
)
var TarCmd = &cmds.Command{
@ -49,11 +49,11 @@ represent it.
if !it.Next() && it.Err() != nil {
return it.Err()
}
if files.FileFrom(it) == nil {
if files.FileFromEntry(it) == nil {
return fmt.Errorf("expected a regular file")
}
node, err := tar.ImportTar(req.Context, files.FileFrom(it), nd.DAG)
node, err := tar.ImportTar(req.Context, files.FileFromEntry(it), nd.DAG)
if err != nil {
return err
}

View File

@ -19,7 +19,7 @@ import (
var rnd = rand.New(rand.NewSource(0x62796532303137))
func addTestObject(ctx context.Context, api coreiface.CoreAPI) (coreiface.Path, error) {
return api.Unixfs().Add(ctx, files.FileFrom(&io.LimitedReader{R: rnd, N: 4092}))
return api.Unixfs().Add(ctx, files.NewReaderFile(&io.LimitedReader{R: rnd, N: 4092}))
}
func appendPath(p coreiface.Path, sub string) coreiface.Path {

View File

@ -136,33 +136,33 @@ func makeAPI(ctx context.Context) (*core.IpfsNode, coreiface.CoreAPI, error) {
func strFile(data string) func() files.Node {
return func() files.Node {
return files.FileFrom([]byte(data))
return files.NewBytesFile([]byte(data))
}
}
func twoLevelDir() func() files.Node {
return func() files.Node {
return files.DirFrom(map[string]files.Node{
"abc": files.DirFrom(map[string]files.Node{
"def": files.FileFrom([]byte("world")),
return files.NewMapDirectory(map[string]files.Node{
"abc": files.NewMapDirectory(map[string]files.Node{
"def": files.NewBytesFile([]byte("world")),
}),
"bar": files.FileFrom([]byte("hello2")),
"foo": files.FileFrom([]byte("hello1")),
"bar": files.NewBytesFile([]byte("hello2")),
"foo": files.NewBytesFile([]byte("hello1")),
})
}
}
func flatDir() files.Node {
return files.DirFrom(map[string]files.Node{
"bar": files.FileFrom([]byte("hello2")),
"foo": files.FileFrom([]byte("hello1")),
return files.NewMapDirectory(map[string]files.Node{
"bar": files.NewBytesFile([]byte("hello2")),
"foo": files.NewBytesFile([]byte("hello1")),
})
}
func wrapped(name string) func(f files.Node) files.Node {
return func(f files.Node) files.Node {
return files.DirFrom(map[string]files.Node{
return files.NewMapDirectory(map[string]files.Node{
name: f,
})
}
@ -296,7 +296,7 @@ func TestAdd(t *testing.T) {
name: "addWrapped",
path: "/ipfs/QmVE9rNpj5doj7XHzp5zMUxD7BJgXEqx4pe3xZ3JBReWHE",
data: func() files.Node {
return files.FileFrom([]byte(helloStr))
return files.NewBytesFile([]byte(helloStr))
},
wrap: "foo",
expect: wrapped("foo"),
@ -306,7 +306,7 @@ func TestAdd(t *testing.T) {
name: "addNotWrappedDirFile",
path: hello,
data: func() files.Node {
return files.FileFrom([]byte(helloStr))
return files.NewBytesFile([]byte(helloStr))
},
wrap: "foo",
},
@ -314,11 +314,11 @@ func TestAdd(t *testing.T) {
name: "stdinWrapped",
path: "/ipfs/QmU3r81oZycjHS9oaSHw37ootMFuFUw1DvMLKXPsezdtqU",
data: func() files.Node {
return files.FileFrom([]byte(helloStr))
return files.NewBytesFile([]byte(helloStr))
},
expect: func(files.Node) files.Node {
return files.DirFrom(map[string]files.Node{
"QmQy2Dw4Wk7rdJKjThjYXzfFJNaRKRHhHP5gHHXroJMYxk": files.FileFrom([]byte(helloStr)),
return files.NewMapDirectory(map[string]files.Node{
"QmQy2Dw4Wk7rdJKjThjYXzfFJNaRKRHhHP5gHHXroJMYxk": files.NewBytesFile([]byte(helloStr)),
})
},
opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true)},
@ -335,8 +335,8 @@ func TestAdd(t *testing.T) {
return rf
},
expect: func(files.Node) files.Node {
return files.DirFrom(map[string]files.Node{
"test": files.FileFrom([]byte(helloStr)),
return files.NewMapDirectory(map[string]files.Node{
"test": files.NewBytesFile([]byte(helloStr)),
})
},
opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true), options.Unixfs.StdinName("test")},
@ -361,10 +361,10 @@ func TestAdd(t *testing.T) {
{
name: "hiddenFiles",
data: func() files.Node {
return files.DirFrom(map[string]files.Node{
".bar": files.FileFrom([]byte("hello2")),
"bar": files.FileFrom([]byte("hello2")),
"foo": files.FileFrom([]byte("hello1")),
return files.NewMapDirectory(map[string]files.Node{
".bar": files.NewBytesFile([]byte("hello2")),
"bar": files.NewBytesFile([]byte("hello2")),
"foo": files.NewBytesFile([]byte("hello1")),
})
},
wrap: "t",
@ -374,7 +374,7 @@ func TestAdd(t *testing.T) {
{
name: "hiddenFileAlwaysAdded",
data: func() files.Node {
return files.FileFrom([]byte(helloStr))
return files.NewBytesFile([]byte(helloStr))
},
wrap: ".foo",
path: hello,
@ -382,10 +382,10 @@ func TestAdd(t *testing.T) {
{
name: "hiddenFilesNotAdded",
data: func() files.Node {
return files.DirFrom(map[string]files.Node{
".bar": files.FileFrom([]byte("hello2")),
"bar": files.FileFrom([]byte("hello2")),
"foo": files.FileFrom([]byte("hello1")),
return files.NewMapDirectory(map[string]files.Node{
".bar": files.NewBytesFile([]byte("hello2")),
"bar": files.NewBytesFile([]byte("hello2")),
"foo": files.NewBytesFile([]byte("hello1")),
})
},
expect: func(files.Node) files.Node {
@ -432,7 +432,7 @@ func TestAdd(t *testing.T) {
{
name: "progress1M",
data: func() files.Node {
return files.FileFrom(bytes.NewReader(bytes.Repeat([]byte{0}, 1000000)))
return files.NewReaderFile(bytes.NewReader(bytes.Repeat([]byte{0}, 1000000)))
},
path: "/ipfs/QmXXNNbwe4zzpdMg62ZXvnX1oU7MwSrQ3vAEtuwFKCm1oD",
events: []coreiface.AddEvent{
@ -456,8 +456,8 @@ func TestAdd(t *testing.T) {
data := testCase.data()
if testCase.wrap != "" {
data = files.NewSliceFile([]files.DirEntry{
files.FileEntry(testCase.wrap, data),
data = files.NewMapDirectory(map[string]files.Node{
testCase.wrap: data,
})
}
@ -868,13 +868,13 @@ func TestAddCloses(t *testing.T) {
t.Error(err)
}
n4 := &closeTestF{files.FileFrom([]byte("foo")), false, t}
d3 := &closeTestD{files.DirFrom(map[string]files.Node{
n4 := &closeTestF{files.NewBytesFile([]byte("foo")), false, t}
d3 := &closeTestD{files.NewMapDirectory(map[string]files.Node{
"sub": n4,
}), false, t}
n2 := &closeTestF{files.FileFrom([]byte("bar")), false, t}
n1 := &closeTestF{files.FileFrom([]byte("baz")), false, t}
d0 := &closeTestD{files.DirFrom(map[string]files.Node{
n2 := &closeTestF{files.NewBytesFile([]byte("bar")), false, t}
n1 := &closeTestF{files.NewBytesFile([]byte("baz")), false, t}
d0 := &closeTestD{files.NewMapDirectory(map[string]files.Node{
"a": d3,
"b": n1,
"c": n2,

View File

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
@ -14,23 +13,23 @@ import (
"strings"
"time"
core "github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core"
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
"github.com/ipfs/go-ipfs/dagutils"
humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
"gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
chunker "gx/ipfs/QmR4QQVkBZsZENRjYFVi8dEtPL3daZRNKk24m4r6WKJHNm/go-ipfs-chunker"
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
routing "gx/ipfs/QmRASJXJUFygM5qU4YrH7k7jD6S4Hg8nJmgqJ4bYJvLatd/go-libp2p-routing"
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
path "gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path"
resolver "gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path/resolver"
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
"gx/ipfs/QmRASJXJUFygM5qU4YrH7k7jD6S4Hg8nJmgqJ4bYJvLatd/go-libp2p-routing"
"gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
"gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path"
"gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path/resolver"
ft "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs"
"gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs/importer"
uio "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs/io"
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
dag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
multibase "gx/ipfs/QmekxXDhCxCJRNuzmHreuaT3BsuJcsjcXWNrtV9C8DRHtd/go-multibase"
"gx/ipfs/QmekxXDhCxCJRNuzmHreuaT3BsuJcsjcXWNrtV9C8DRHtd/go-multibase"
)
const (
@ -390,7 +389,7 @@ func (i *gatewayHandler) serveFile(w http.ResponseWriter, req *http.Request, nam
}
func (i *gatewayHandler) postHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {
p, err := i.api.Unixfs().Add(ctx, files.NewReaderFile(ioutil.NopCloser(r.Body), nil))
p, err := i.api.Unixfs().Add(ctx, files.NewReaderFile(r.Body))
if err != nil {
internalWebError(w, err)
return

View File

@ -5,26 +5,25 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
gopath "path"
"path/filepath"
"strconv"
core "github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core"
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
"github.com/ipfs/go-ipfs/pin"
chunker "gx/ipfs/QmR4QQVkBZsZENRjYFVi8dEtPL3daZRNKk24m4r6WKJHNm/go-ipfs-chunker"
posinfo "gx/ipfs/QmR6YMs8EkXQLXNwQKxLnQp2VBZSepoEJ8KCZAyanJHhJu/go-ipfs-posinfo"
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
"gx/ipfs/QmR6YMs8EkXQLXNwQKxLnQp2VBZSepoEJ8KCZAyanJHhJu/go-ipfs-posinfo"
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
bstore "gx/ipfs/QmS2aqUZLJp8kF1ihE5rvDGE5LvmKDPnx32w9Z1BW9xLV5/go-ipfs-blockstore"
mfs "gx/ipfs/QmU3iDRUrxyTYdV2j5MuWLFvP1k7w98vD66PLnNChgvUmZ/go-mfs"
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
unixfs "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs"
balanced "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs/importer/balanced"
"gx/ipfs/QmU3iDRUrxyTYdV2j5MuWLFvP1k7w98vD66PLnNChgvUmZ/go-mfs"
"gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
"gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs"
"gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs/importer/balanced"
ihelper "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs/importer/helpers"
trickle "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs/importer/trickle"
"gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs/importer/trickle"
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log"
dag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
@ -341,7 +340,6 @@ func AddR(n *core.IpfsNode, root string) (key string, err error) {
// Returns the path of the added file ("<dir hash>/filename"), the DAG node of
// the directory, and and error if any.
func AddWrapped(n *core.IpfsNode, r io.Reader, filename string) (string, ipld.Node, error) {
file := files.NewReaderFile(ioutil.NopCloser(r), nil)
fileAdder, err := NewAdder(n.Context(), n.Pinning, n.Blockstore, n.DAG)
if err != nil {
return "", nil, err
@ -350,7 +348,7 @@ func AddWrapped(n *core.IpfsNode, r io.Reader, filename string) (string, ipld.No
defer n.Blockstore.PinLock().Unlock()
err = fileAdder.addFile(filename, file)
err = fileAdder.addFile(filename, files.NewReaderFile(r))
if err != nil {
return "", nil, err
}

View File

@ -71,15 +71,15 @@ func TestAddGCLive(t *testing.T) {
}
adder.Out = out
rfa := files.FileFrom([]byte("testfileA"))
rfa := files.NewBytesFile([]byte("testfileA"))
// make two files with pipes so we can 'pause' the add for timing of the test
piper, pipew := io.Pipe()
hangfile := files.FileFrom(piper)
hangfile := files.NewReaderFile(piper)
rfd := files.FileFrom([]byte("testfileD"))
rfd := files.NewBytesFile([]byte("testfileD"))
slf := files.DirFrom(map[string]files.Node{
slf := files.NewMapDirectory(map[string]files.Node{
"a": rfa,
"b": hangfile,
"d": rfd,