This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change 3131 "glob" : " ^7.1.1" ,
3232 "glob-escape" : " 0.0.2" ,
3333 "ipfs-block" : " ^0.5.1" ,
34+ "ipfs-unixfs" : " ^0.1.8" ,
3435 "ipld-dag-pb" : " ^0.9.3" ,
3536 "is-ipfs" : " ^0.2.1" ,
3637 "isstream" : " ^0.1.2" ,
6263 "eslint-plugin-react" : " ^6.8.0" ,
6364 "gulp" : " ^3.9.1" ,
6465 "hapi" : " ^16.0.1" ,
65- "interface-ipfs-core" : " ^0.22.0 " ,
66+ "interface-ipfs-core" : " ^0.22.1 " ,
6667 "ipfsd-ctl" : " ^0.17.0" ,
6768 "pre-commit" : " ^1.2.0" ,
6869 "socket.io" : " ^1.7.1" ,
116117 "url" : " https://github.com/ipfs/js-ipfs-api/issues"
117118 },
118119 "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')
1111const lruOptions = {
1212 max : 128
1313}
14-
14+ const Unixfs = require ( 'ipfs-unixfs' )
1515const cache = LRU ( lruOptions )
1616
1717module . exports = ( send ) => {
@@ -253,15 +253,31 @@ module.exports = (send) => {
253253 args : multihash
254254 } , callback )
255255 } ) ,
256- new : promisify ( ( callback ) => {
256+ new : promisify ( ( template , callback ) => {
257+ if ( typeof template === 'function' ) {
258+ callback = template
259+ template = undefined
260+ }
257261 send ( {
258- path : 'object/new'
262+ path : 'object/new' ,
263+ args : template
259264 } , ( err , result ) => {
260265 if ( err ) {
261266 return callback ( err )
262267 }
263268
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 ) => {
265281 if ( err ) {
266282 return callback ( err )
267283 }
You can’t perform that action at this time.
0 commit comments