6
6
"io"
7
7
"os"
8
8
9
+ files "github.com/ipfs/go-ipfs-files"
10
+
9
11
util "github.com/ipfs/go-ipfs/blocks/blockstoreutil"
10
12
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
11
13
@@ -129,7 +131,7 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
129
131
},
130
132
131
133
Arguments : []cmds.Argument {
132
- cmds .FileArg ("data" , true , false , "The data to be stored as an IPFS block." ).EnableStdin (),
134
+ cmds .FileArg ("data" , true , true , "The data to be stored as an IPFS block." ).EnableStdin (),
133
135
},
134
136
Options : []cmds.Option {
135
137
cmds .StringOption (blockFormatOptionName , "f" , "cid format for blocks to be created with." ),
@@ -143,11 +145,6 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
143
145
return err
144
146
}
145
147
146
- file , err := cmdenv .GetFileArg (req .Files .Entries ())
147
- if err != nil {
148
- return err
149
- }
150
-
151
148
mhtype , _ := req .Options [mhtypeOptionName ].(string )
152
149
mhtval , ok := mh .Names [mhtype ]
153
150
if ! ok {
@@ -170,18 +167,31 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
170
167
171
168
pin , _ := req .Options [pinOptionName ].(bool )
172
169
173
- p , err := api .Block ().Put (req .Context , file ,
174
- options .Block .Hash (mhtval , mhlen ),
175
- options .Block .Format (format ),
176
- options .Block .Pin (pin ))
177
- if err != nil {
178
- return err
170
+ it := req .Files .Entries ()
171
+ for it .Next () {
172
+ file := files .FileFromEntry (it )
173
+ if file == nil {
174
+ return errors .New ("expected a file" )
175
+ }
176
+
177
+ p , err := api .Block ().Put (req .Context , file ,
178
+ options .Block .Hash (mhtval , mhlen ),
179
+ options .Block .Format (format ),
180
+ options .Block .Pin (pin ))
181
+ if err != nil {
182
+ return err
183
+ }
184
+
185
+ err = res .Emit (& BlockStat {
186
+ Key : p .Path ().Cid ().String (),
187
+ Size : p .Size (),
188
+ })
189
+ if err != nil {
190
+ return err
191
+ }
179
192
}
180
193
181
- return cmds .EmitOnce (res , & BlockStat {
182
- Key : p .Path ().Cid ().String (),
183
- Size : p .Size (),
184
- })
194
+ return it .Err ()
185
195
},
186
196
Encoders : cmds.EncoderMap {
187
197
cmds .Text : cmds .MakeTypedEncoder (func (req * cmds.Request , w io.Writer , bs * BlockStat ) error {
0 commit comments