files2.0: refactored helpers
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
Dec 13, 2018 at 22:41 UTC
eed806a58b6eab0c1a703250ae6d607fdfc64bd3
13 files changed
+83
-86
cmd/ipfs/init.go
+3
-3
@@ -16,10 +16,10 @@ import (
16
namesys "github.com/ipfs/go-ipfs/namesys"
17
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
18
19
+ "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
20
"gx/ipfs/QmYyzmMnhNTtoXx5ttgUaRdHHckYnQWjPL98hgLAR2QLDD/go-ipfs-config"
21
"gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
22
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
22
- "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files"
23
)
24
25
const (
@@ -90,12 +90,12 @@ environment variable:
90
if !it.Next() && it.Err() != nil {
91
return it.Err()
92
}
93
- if files.FileFrom(it) == nil {
93
+ if files.FileFromEntry(it) == nil {
94
return fmt.Errorf("expected a regular file")
95
}
96
97
conf = &config.Config{}
98
- if err := json.NewDecoder(files.FileFrom(it)).Decode(conf); err != nil {
98
+ if err := json.NewDecoder(files.FileFromEntry(it)).Decode(conf); err != nil {
99
return err
100
}
101
}
core/commands/block.go
+3
-3
@@ -11,9 +11,9 @@ import (
11
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
12
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
13
14
+ files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
15
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
16
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
16
- files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files"
17
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
18
)
19
@@ -158,7 +158,7 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
158
if !it.Next() && it.Err() != nil {
159
return it.Err()
160
}
161
- if files.FileFrom(it) == nil {
161
+ if files.FileFromEntry(it) == nil {
162
return fmt.Errorf("expected a regular file")
163
}
164
@@ -182,7 +182,7 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
182
}
183
}
184
185
- p, err := api.Block().Put(req.Context, files.FileFrom(it), options.Block.Hash(mhtval, mhlen), options.Block.Format(format))
185
+ p, err := api.Block().Put(req.Context, files.FileFromEntry(it), options.Block.Hash(mhtval, mhlen), options.Block.Format(format))
186
if err != nil {
187
return err
188
}
core/commands/config.go
+3
-3
@@ -15,10 +15,10 @@ import (
15
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
16
17
"gx/ipfs/QmP2i47tnU23ijdshrZtuvrSkQPtf9HhsMb9fwGVe8owj2/jsondiff"
18
+ files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
19
config "gx/ipfs/QmYyzmMnhNTtoXx5ttgUaRdHHckYnQWjPL98hgLAR2QLDD/go-ipfs-config"
20
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
21
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
21
- files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files"
22
)
23
24
// ConfigUpdateOutput is config profile apply command's output
@@ -285,10 +285,10 @@ can't be undone.
285
if !it.Next() && it.Err() != nil {
286
return it.Err()
287
}
288
- if files.FileFrom(it) == nil {
288
+ if files.FileFromEntry(it) == nil {
289
return fmt.Errorf("expected a regular file")
290
}
291
- file := files.FileFrom(it)
291
+ file := files.FileFromEntry(it)
292
defer file.Close()
293
294
return replaceConfig(r, file)
core/commands/dag/dag.go
+3
-3
@@ -10,11 +10,11 @@ import (
10
"github.com/ipfs/go-ipfs/pin"
11
12
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
13
+ files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
14
path "gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path"
15
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
16
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
17
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
17
- files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files"
18
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
19
)
20
@@ -95,10 +95,10 @@ into an object of the specified format.
95
96
it := req.Files.Entries()
97
for it.Next() {
98
- if files.FileFrom(it) == nil {
98
+ if files.FileFromEntry(it) == nil {
99
return fmt.Errorf("expected a regular file")
100
}
101
- nds, err := coredag.ParseInputs(ienc, format, files.FileFrom(it), mhType, -1)
101
+ nds, err := coredag.ParseInputs(ienc, format, files.FileFromEntry(it), mhType, -1)
102
if err != nil {
103
return err
104
}
core/commands/files.go
+3
-3
@@ -18,6 +18,7 @@ import (
18
bservice "gx/ipfs/QmPoh3SrQzFBWtdGK6qmHDV4EanKR6kYPj4DD3J2NLoEmZ/go-blockservice"
19
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
20
mfs "gx/ipfs/QmU3iDRUrxyTYdV2j5MuWLFvP1k7w98vD66PLnNChgvUmZ/go-mfs"
21
+ files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
22
offline "gx/ipfs/QmYZwey1thDTynSrvd6qQkX24UpTka6TFhQ2v569UpoqxD/go-ipfs-exchange-offline"
23
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
24
ft "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs"
@@ -25,7 +26,6 @@ import (
26
logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log"
27
dag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
28
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
28
- files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files"
29
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
30
)
31
@@ -774,11 +774,11 @@ stat' on the file or any of its ancestors.
774
if !it.Next() && it.Err() != nil {
775
return it.Err()
776
}
777
- if files.FileFrom(it) == nil {
777
+ if files.FileFromEntry(it) == nil {
778
return fmt.Errorf("expected a regular file")
779
}
780
781
- var r io.Reader = files.FileFrom(it)
781
+ var r io.Reader = files.FileFromEntry(it)
782
if countfound {
783
r = io.LimitReader(r, int64(count))
784
}
core/commands/object/object.go
+3
-3
@@ -13,11 +13,11 @@ import (
13
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
14
15
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
16
+ files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
17
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
18
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
19
dag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
20
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
20
- files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files"
21
)
22
23
type Node struct {
@@ -396,7 +396,7 @@ And then run:
396
if !it.Next() && it.Err() != nil {
397
return it.Err()
398
}
399
- if files.FileFrom(it) == nil {
399
+ if files.FileFromEntry(it) == nil {
400
return fmt.Errorf("expected a regular file")
401
}
402
@@ -415,7 +415,7 @@ And then run:
415
return err
416
}
417
418
- p, err := api.Object().Put(req.Context, files.FileFrom(it),
418
+ p, err := api.Object().Put(req.Context, files.FileFromEntry(it),
419
options.Object.DataType(datafieldenc),
420
options.Object.InputEnc(inputenc),
421
options.Object.Pin(dopin))
core/commands/object/patch.go
+5
-5
@@ -8,9 +8,9 @@ import (
8
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
9
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
10
11
+ "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
12
"gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
13
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
13
- "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files"
14
)
15
16
var ObjectPatchCmd = &cmds.Command{
@@ -65,11 +65,11 @@ the limit will not be respected by the network.
65
if !it.Next() && it.Err() != nil {
66
return it.Err()
67
}
68
- if files.FileFrom(it) == nil {
68
+ if files.FileFromEntry(it) == nil {
69
return fmt.Errorf("expected a regular file")
70
}
71
72
- p, err := api.Object().AppendData(req.Context, root, files.FileFrom(it))
72
+ p, err := api.Object().AppendData(req.Context, root, files.FileFromEntry(it))
73
if err != nil {
74
return err
75
}
@@ -115,11 +115,11 @@ Example:
115
if !it.Next() && it.Err() != nil {
116
return it.Err()
117
}
118
- if files.FileFrom(it) == nil {
118
+ if files.FileFromEntry(it) == nil {
119
return fmt.Errorf("expected a regular file")
120
}
121
122
- p, err := api.Object().SetData(req.Context, root, files.FileFrom(it))
122
+ p, err := api.Object().SetData(req.Context, root, files.FileFromEntry(it))
123
if err != nil {
124
return err
125
}
core/commands/tar.go
+3
-3
@@ -9,11 +9,11 @@ import (
9
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
10
tar "github.com/ipfs/go-ipfs/tar"
11
12
+ files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
13
"gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path"
14
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
15
dag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
16
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
16
- files "gx/ipfs/QmeaQRmnRog7NxLEWHP9zSTkics4cbgwBVa7q49LmBowDr/go-ipfs-files"
17
)
18
19
var TarCmd = &cmds.Command{
@@ -49,11 +49,11 @@ represent it.
49
if !it.Next() && it.Err() != nil {
50
return it.Err()
51
}
52
- if files.FileFrom(it) == nil {
52
+ if files.FileFromEntry(it) == nil {
53
return fmt.Errorf("expected a regular file")
54
}
55
56
- node, err := tar.ImportTar(req.Context, files.FileFrom(it), nd.DAG)
56
+ node, err := tar.ImportTar(req.Context, files.FileFromEntry(it), nd.DAG)
57
if err != nil {
58
return err
59
}
core/coreapi/name_test.go
+1
-1
@@ -19,7 +19,7 @@ import (
19
var rnd = rand.New(rand.NewSource(0x62796532303137))
20
21
func addTestObject(ctx context.Context, api coreiface.CoreAPI) (coreiface.Path, error) {
22
- return api.Unixfs().Add(ctx, files.FileFrom(&io.LimitedReader{R: rnd, N: 4092}))
22
+ return api.Unixfs().Add(ctx, files.NewReaderFile(&io.LimitedReader{R: rnd, N: 4092}))
23
}
24
25
func appendPath(p coreiface.Path, sub string) coreiface.Path {
core/coreapi/unixfs_test.go
+34
-34
@@ -136,33 +136,33 @@ func makeAPI(ctx context.Context) (*core.IpfsNode, coreiface.CoreAPI, error) {
136
137
func strFile(data string) func() files.Node {
138
return func() files.Node {
139
- return files.FileFrom([]byte(data))
139
+ return files.NewBytesFile([]byte(data))
140
}
141
}
142
143
func twoLevelDir() func() files.Node {
144
return func() files.Node {
145
- return files.DirFrom(map[string]files.Node{
146
- "abc": files.DirFrom(map[string]files.Node{
147
- "def": files.FileFrom([]byte("world")),
145
+ return files.NewMapDirectory(map[string]files.Node{
146
+ "abc": files.NewMapDirectory(map[string]files.Node{
147
+ "def": files.NewBytesFile([]byte("world")),
148
}),
149
150
- "bar": files.FileFrom([]byte("hello2")),
151
- "foo": files.FileFrom([]byte("hello1")),
150
+ "bar": files.NewBytesFile([]byte("hello2")),
151
+ "foo": files.NewBytesFile([]byte("hello1")),
152
})
153
}
154
}
155
156
func flatDir() files.Node {
157
- return files.DirFrom(map[string]files.Node{
158
- "bar": files.FileFrom([]byte("hello2")),
159
- "foo": files.FileFrom([]byte("hello1")),
157
+ return files.NewMapDirectory(map[string]files.Node{
158
+ "bar": files.NewBytesFile([]byte("hello2")),
159
+ "foo": files.NewBytesFile([]byte("hello1")),
160
})
161
}
162
163
func wrapped(name string) func(f files.Node) files.Node {
164
return func(f files.Node) files.Node {
165
- return files.DirFrom(map[string]files.Node{
165
+ return files.NewMapDirectory(map[string]files.Node{
166
name: f,
167
})
168
}
@@ -296,7 +296,7 @@ func TestAdd(t *testing.T) {
296
name: "addWrapped",
297
path: "/ipfs/QmVE9rNpj5doj7XHzp5zMUxD7BJgXEqx4pe3xZ3JBReWHE",
298
data: func() files.Node {
299
- return files.FileFrom([]byte(helloStr))
299
+ return files.NewBytesFile([]byte(helloStr))
300
},
301
wrap: "foo",
302
expect: wrapped("foo"),
@@ -306,7 +306,7 @@ func TestAdd(t *testing.T) {
306
name: "addNotWrappedDirFile",
307
path: hello,
308
data: func() files.Node {
309
- return files.FileFrom([]byte(helloStr))
309
+ return files.NewBytesFile([]byte(helloStr))
310
},
311
wrap: "foo",
312
},
@@ -314,11 +314,11 @@ func TestAdd(t *testing.T) {
314
name: "stdinWrapped",
315
path: "/ipfs/QmU3r81oZycjHS9oaSHw37ootMFuFUw1DvMLKXPsezdtqU",
316
data: func() files.Node {
317
- return files.FileFrom([]byte(helloStr))
317
+ return files.NewBytesFile([]byte(helloStr))
318
},
319
expect: func(files.Node) files.Node {
320
- return files.DirFrom(map[string]files.Node{
321
- "QmQy2Dw4Wk7rdJKjThjYXzfFJNaRKRHhHP5gHHXroJMYxk": files.FileFrom([]byte(helloStr)),
320
+ return files.NewMapDirectory(map[string]files.Node{
321
+ "QmQy2Dw4Wk7rdJKjThjYXzfFJNaRKRHhHP5gHHXroJMYxk": files.NewBytesFile([]byte(helloStr)),
322
})
323
},
324
opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true)},
@@ -335,8 +335,8 @@ func TestAdd(t *testing.T) {
335
return rf
336
},
337
expect: func(files.Node) files.Node {
338
- return files.DirFrom(map[string]files.Node{
339
- "test": files.FileFrom([]byte(helloStr)),
338
+ return files.NewMapDirectory(map[string]files.Node{
339
+ "test": files.NewBytesFile([]byte(helloStr)),
340
})
341
},
342
opts: []options.UnixfsAddOption{options.Unixfs.Wrap(true), options.Unixfs.StdinName("test")},
@@ -361,10 +361,10 @@ func TestAdd(t *testing.T) {
361
{
362
name: "hiddenFiles",
363
data: func() files.Node {
364
- return files.DirFrom(map[string]files.Node{
365
- ".bar": files.FileFrom([]byte("hello2")),
366
- "bar": files.FileFrom([]byte("hello2")),
367
- "foo": files.FileFrom([]byte("hello1")),
364
+ return files.NewMapDirectory(map[string]files.Node{
365
+ ".bar": files.NewBytesFile([]byte("hello2")),
366
+ "bar": files.NewBytesFile([]byte("hello2")),
367
+ "foo": files.NewBytesFile([]byte("hello1")),
368
})
369
},
370
wrap: "t",
@@ -374,7 +374,7 @@ func TestAdd(t *testing.T) {
374
{
375
name: "hiddenFileAlwaysAdded",
376
data: func() files.Node {
377
- return files.FileFrom([]byte(helloStr))
377
+ return files.NewBytesFile([]byte(helloStr))
378
},
379
wrap: ".foo",
380
path: hello,
@@ -382,10 +382,10 @@ func TestAdd(t *testing.T) {
382
{
383
name: "hiddenFilesNotAdded",
384
data: func() files.Node {
385
- return files.DirFrom(map[string]files.Node{
386
- ".bar": files.FileFrom([]byte("hello2")),
387
- "bar": files.FileFrom([]byte("hello2")),
388
- "foo": files.FileFrom([]byte("hello1")),
385
+ return files.NewMapDirectory(map[string]files.Node{
386
+ ".bar": files.NewBytesFile([]byte("hello2")),
387
+ "bar": files.NewBytesFile([]byte("hello2")),
388
+ "foo": files.NewBytesFile([]byte("hello1")),
389
})
390
},
391
expect: func(files.Node) files.Node {
@@ -432,7 +432,7 @@ func TestAdd(t *testing.T) {
432
{
433
name: "progress1M",
434
data: func() files.Node {
435
- return files.FileFrom(bytes.NewReader(bytes.Repeat([]byte{0}, 1000000)))
435
+ return files.NewReaderFile(bytes.NewReader(bytes.Repeat([]byte{0}, 1000000)))
436
},
437
path: "/ipfs/QmXXNNbwe4zzpdMg62ZXvnX1oU7MwSrQ3vAEtuwFKCm1oD",
438
events: []coreiface.AddEvent{
@@ -456,8 +456,8 @@ func TestAdd(t *testing.T) {
456
457
data := testCase.data()
458
if testCase.wrap != "" {
459
- data = files.NewSliceFile([]files.DirEntry{
460
- files.FileEntry(testCase.wrap, data),
459
+ data = files.NewMapDirectory(map[string]files.Node{
460
+ testCase.wrap: data,
461
})
462
}
463
@@ -868,13 +868,13 @@ func TestAddCloses(t *testing.T) {
868
t.Error(err)
869
}
870
871
- n4 := &closeTestF{files.FileFrom([]byte("foo")), false, t}
872
- d3 := &closeTestD{files.DirFrom(map[string]files.Node{
871
+ n4 := &closeTestF{files.NewBytesFile([]byte("foo")), false, t}
872
+ d3 := &closeTestD{files.NewMapDirectory(map[string]files.Node{
873
"sub": n4,
874
}), false, t}
875
- n2 := &closeTestF{files.FileFrom([]byte("bar")), false, t}
876
- n1 := &closeTestF{files.FileFrom([]byte("baz")), false, t}
877
- d0 := &closeTestD{files.DirFrom(map[string]files.Node{
875
+ n2 := &closeTestF{files.NewBytesFile([]byte("bar")), false, t}
876
+ n1 := &closeTestF{files.NewBytesFile([]byte("baz")), false, t}
877
+ d0 := &closeTestD{files.NewMapDirectory(map[string]files.Node{
878
"a": d3,
879
"b": n1,
880
"c": n2,
core/corehttp/gateway_handler.go
+9
-10
@@ -5,7 +5,6 @@ import (
5
"errors"
6
"fmt"
7
"io"
8
- "io/ioutil"
8
"net/http"
9
"net/url"
10
"os"
@@ -14,23 +13,23 @@ import (
13
"strings"
14
"time"
15
17
- core "github.com/ipfs/go-ipfs/core"
16
+ "github.com/ipfs/go-ipfs/core"
17
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
18
"github.com/ipfs/go-ipfs/dagutils"
19
21
- humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
20
+ "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
21
chunker "gx/ipfs/QmR4QQVkBZsZENRjYFVi8dEtPL3daZRNKk24m4r6WKJHNm/go-ipfs-chunker"
23
- cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
24
- routing "gx/ipfs/QmRASJXJUFygM5qU4YrH7k7jD6S4Hg8nJmgqJ4bYJvLatd/go-libp2p-routing"
25
- files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
26
- path "gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path"
27
- resolver "gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path/resolver"
22
+ "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
23
+ "gx/ipfs/QmRASJXJUFygM5qU4YrH7k7jD6S4Hg8nJmgqJ4bYJvLatd/go-libp2p-routing"
24
+ "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
25
+ "gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path"
26
+ "gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path/resolver"
27
ft "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs"
28
"gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs/importer"
29
uio "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs/io"
30
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
31
dag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
33
- multibase "gx/ipfs/QmekxXDhCxCJRNuzmHreuaT3BsuJcsjcXWNrtV9C8DRHtd/go-multibase"
32
+ "gx/ipfs/QmekxXDhCxCJRNuzmHreuaT3BsuJcsjcXWNrtV9C8DRHtd/go-multibase"
33
)
34
35
const (
@@ -390,7 +389,7 @@ func (i *gatewayHandler) serveFile(w http.ResponseWriter, req *http.Request, nam
389
}
390
391
func (i *gatewayHandler) postHandler(ctx context.Context, w http.ResponseWriter, r *http.Request) {
393
- p, err := i.api.Unixfs().Add(ctx, files.NewReaderFile(ioutil.NopCloser(r.Body), nil))
392
+ p, err := i.api.Unixfs().Add(ctx, files.NewReaderFile(r.Body))
393
if err != nil {
394
internalWebError(w, err)
395
return
core/coreunix/add.go
+9
-11
@@ -5,26 +5,25 @@ import (
5
"errors"
6
"fmt"
7
"io"
8
- "io/ioutil"
8
"os"
9
gopath "path"
10
"path/filepath"
11
"strconv"
12
14
- core "github.com/ipfs/go-ipfs/core"
13
+ "github.com/ipfs/go-ipfs/core"
14
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
15
"github.com/ipfs/go-ipfs/pin"
16
17
chunker "gx/ipfs/QmR4QQVkBZsZENRjYFVi8dEtPL3daZRNKk24m4r6WKJHNm/go-ipfs-chunker"
19
- posinfo "gx/ipfs/QmR6YMs8EkXQLXNwQKxLnQp2VBZSepoEJ8KCZAyanJHhJu/go-ipfs-posinfo"
20
- cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
18
+ "gx/ipfs/QmR6YMs8EkXQLXNwQKxLnQp2VBZSepoEJ8KCZAyanJHhJu/go-ipfs-posinfo"
19
+ "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
20
bstore "gx/ipfs/QmS2aqUZLJp8kF1ihE5rvDGE5LvmKDPnx32w9Z1BW9xLV5/go-ipfs-blockstore"
22
- mfs "gx/ipfs/QmU3iDRUrxyTYdV2j5MuWLFvP1k7w98vD66PLnNChgvUmZ/go-mfs"
23
- files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
24
- unixfs "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs"
25
- balanced "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs/importer/balanced"
21
+ "gx/ipfs/QmU3iDRUrxyTYdV2j5MuWLFvP1k7w98vD66PLnNChgvUmZ/go-mfs"
22
+ "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
23
+ "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs"
24
+ "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs/importer/balanced"
25
ihelper "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs/importer/helpers"
27
- trickle "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs/importer/trickle"
26
+ "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs/importer/trickle"
27
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
28
logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log"
29
dag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
@@ -341,7 +340,6 @@ func AddR(n *core.IpfsNode, root string) (key string, err error) {
340
// Returns the path of the added file ("<dir hash>/filename"), the DAG node of
341
// the directory, and and error if any.
342
func AddWrapped(n *core.IpfsNode, r io.Reader, filename string) (string, ipld.Node, error) {
344
- file := files.NewReaderFile(ioutil.NopCloser(r), nil)
343
fileAdder, err := NewAdder(n.Context(), n.Pinning, n.Blockstore, n.DAG)
344
if err != nil {
345
return "", nil, err
@@ -350,7 +348,7 @@ func AddWrapped(n *core.IpfsNode, r io.Reader, filename string) (string, ipld.No
348
349
defer n.Blockstore.PinLock().Unlock()
350
353
- err = fileAdder.addFile(filename, file)
351
+ err = fileAdder.addFile(filename, files.NewReaderFile(r))
352
if err != nil {
353
return "", nil, err
354
}
core/coreunix/add_test.go
+4
-4
@@ -71,15 +71,15 @@ func TestAddGCLive(t *testing.T) {
71
}
72
adder.Out = out
73
74
- rfa := files.FileFrom([]byte("testfileA"))
74
+ rfa := files.NewBytesFile([]byte("testfileA"))
75
76
// make two files with pipes so we can 'pause' the add for timing of the test
77
piper, pipew := io.Pipe()
78
- hangfile := files.FileFrom(piper)
78
+ hangfile := files.NewReaderFile(piper)
79
80
- rfd := files.FileFrom([]byte("testfileD"))
80
+ rfd := files.NewBytesFile([]byte("testfileD"))
81
82
- slf := files.DirFrom(map[string]files.Node{
82
+ slf := files.NewMapDirectory(map[string]files.Node{
83
"a": rfa,
84
"b": hangfile,
85
"d": rfd,