This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree 2 files changed +23
-6
lines changed
2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change 31
31
"glob" : " ^7.1.1" ,
32
32
"glob-escape" : " 0.0.2" ,
33
33
"ipfs-block" : " ^0.5.1" ,
34
+ "ipfs-unixfs" : " ^0.1.8" ,
34
35
"ipld-dag-pb" : " ^0.9.3" ,
35
36
"is-ipfs" : " ^0.2.1" ,
36
37
"isstream" : " ^0.1.2" ,
62
63
"eslint-plugin-react" : " ^6.8.0" ,
63
64
"gulp" : " ^3.9.1" ,
64
65
"hapi" : " ^16.0.1" ,
65
- "interface-ipfs-core" : " ^0.22.0 " ,
66
+ "interface-ipfs-core" : " ^0.22.1 " ,
66
67
"ipfsd-ctl" : " ^0.17.0" ,
67
68
"pre-commit" : " ^1.2.0" ,
68
69
"socket.io" : " ^1.7.1" ,
116
117
"url" : " https://github.com/ipfs/js-ipfs-api/issues"
117
118
},
118
119
"homepage" : " https://github.com/ipfs/js-ipfs-api"
119
- }
120
+ }
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ const LRU = require('lru-cache')
11
11
const lruOptions = {
12
12
max : 128
13
13
}
14
-
14
+ const Unixfs = require ( 'ipfs-unixfs' )
15
15
const cache = LRU ( lruOptions )
16
16
17
17
module . exports = ( send ) => {
@@ -253,15 +253,31 @@ module.exports = (send) => {
253
253
args : multihash
254
254
} , callback )
255
255
} ) ,
256
- new : promisify ( ( callback ) => {
256
+ new : promisify ( ( template , callback ) => {
257
+ if ( typeof template === 'function' ) {
258
+ callback = template
259
+ template = undefined
260
+ }
257
261
send ( {
258
- path : 'object/new'
262
+ path : 'object/new' ,
263
+ args : template
259
264
} , ( err , result ) => {
260
265
if ( err ) {
261
266
return callback ( err )
262
267
}
263
268
264
- DAGNode . create ( new Buffer ( 0 ) , ( err , node ) => {
269
+ let data
270
+
271
+ if ( template ) {
272
+ if ( template !== 'unixfs-dir' ) {
273
+ return callback ( new Error ( 'unkown template: ' + template ) )
274
+ }
275
+ data = ( new Unixfs ( 'directory' ) ) . marshal ( )
276
+ } else {
277
+ data = new Buffer ( 0 )
278
+ }
279
+
280
+ DAGNode . create ( data , ( err , node ) => {
265
281
if ( err ) {
266
282
return callback ( err )
267
283
}
You can’t perform that action at this time.
0 commit comments