This repository was archived by the owner on Aug 11, 2021. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3737 "homepage" : " https://github.com/ipld/js-ipld-dag-cbor" ,
3838 "dependencies" : {
3939 "async" : " ^2.1.4" ,
40+ "borc" : " ^2.0.0" ,
4041 "bs58" : " ^3.1.0" ,
41- "cbor" : " ^3.0.0" ,
4242 "cids" : " ^0.2.0" ,
4343 "multihashes" : " ^0.3.0" ,
4444 "multihashing-async" : " ^0.3.0" ,
5858 " npmcdn-to-unpkg-bot <npmcdn-to-unpkg-bot@users.noreply.github.com>" ,
5959 " wanderer <mjbecze@gmail.com>"
6060 ]
61- }
61+ }
Original file line number Diff line number Diff line change 11'use strict'
22
3- const cbor = require ( 'cbor ' )
3+ const cbor = require ( 'borc ' )
44const multihashing = require ( 'multihashing-async' )
55const CID = require ( 'cids' )
66const waterfall = require ( 'async/waterfall' )
7+ const setImmediate = require ( 'async/setImmediate' )
78
89const resolver = require ( './resolver' )
910
@@ -15,13 +16,28 @@ exports.serialize = (dagNode, callback) => {
1516 serialized = cbor . encode ( dagNode )
1617 } catch ( err ) {
1718 // return is important, otherwise in case of error the execution would continue
18- return callback ( err )
19+ return setImmediate ( ( ) => {
20+ callback ( err )
21+ } )
1922 }
20- callback ( null , serialized )
23+ setImmediate ( ( ) => {
24+ callback ( null , serialized )
25+ } )
2126}
2227
2328exports . deserialize = ( data , callback ) => {
24- cbor . decodeFirst ( data , callback )
29+ let res
30+ try {
31+ res = cbor . decodeFirst ( data )
32+ } catch ( err ) {
33+ return setImmediate ( ( ) => {
34+ callback ( err )
35+ } )
36+ }
37+
38+ setImmediate ( ( ) => {
39+ callback ( null , res )
40+ } )
2541}
2642
2743exports . cid = ( dagNode , callback ) => {
Original file line number Diff line number Diff line change @@ -104,10 +104,6 @@ describe('IPLD format resolver (local)', () => {
104104 expect ( paths ) . to . eql ( [ {
105105 path : 'name' ,
106106 value : 'I am a node'
107- } , {
108- // TODO: confirm how to represent links in tree
109- path : 'someLink//' ,
110- value : 'LINK'
111107 } , {
112108 path : 'nest/foo/bar' ,
113109 value : 'baz'
@@ -117,6 +113,10 @@ describe('IPLD format resolver (local)', () => {
117113 } , {
118114 path : 'array/1' ,
119115 value : 2
116+ } , {
117+ // TODO: confirm how to represent links in tree
118+ path : 'someLink//' ,
119+ value : 'LINK'
120120 } ] )
121121 done ( )
122122 } )
You can’t perform that action at this time.
0 commit comments