@@ -12,7 +12,7 @@ const {
12
12
DAGNode,
13
13
DAGLink
14
14
} = require ( 'ipld-dag-pb' )
15
- const mh = require ( 'multihashes' )
15
+ const mh = require ( 'multihashing-async' ) . multihash
16
16
const mc = require ( 'multicodec' )
17
17
const exporter = require ( '../src' )
18
18
const importer = require ( 'ipfs-unixfs-importer' )
@@ -38,7 +38,10 @@ describe('exporter', () => {
38
38
options . content = options . content || Buffer . from ( [ 0x01 , 0x02 , 0x03 ] )
39
39
options . links = options . links || [ ]
40
40
41
- const file = new UnixFS ( options . type , options . content )
41
+ const file = new UnixFS ( {
42
+ type : options . type ,
43
+ data : options . content
44
+ } )
42
45
43
46
const node = new DAGNode ( file . marshal ( ) , options . links )
44
47
const cid = await ipld . put ( node , mc . DAG_PB , {
@@ -190,7 +193,10 @@ describe('exporter', () => {
190
193
191
194
it ( 'exports a small file with links' , async ( ) => {
192
195
const content = Buffer . from ( [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] )
193
- const chunk1 = new UnixFS ( 'raw' , content . slice ( 0 , 5 ) )
196
+ const chunk1 = new UnixFS ( {
197
+ type : 'raw' ,
198
+ data : content . slice ( 0 , 5 )
199
+ } )
194
200
const chunkNode1 = new DAGNode ( chunk1 . marshal ( ) )
195
201
const chunkCid1 = await ipld . put ( chunkNode1 , mc . DAG_PB , {
196
202
cidVersion : 0 ,
@@ -204,7 +210,9 @@ describe('exporter', () => {
204
210
hashAlg : mh . names [ 'sha2-256' ]
205
211
} )
206
212
207
- const file = new UnixFS ( 'file' )
213
+ const file = new UnixFS ( {
214
+ type : 'file'
215
+ } )
208
216
file . addBlockSize ( 5 )
209
217
file . addBlockSize ( 5 )
210
218
@@ -830,7 +838,9 @@ describe('exporter', () => {
830
838
foo : 'bar'
831
839
} , mc . DAG_CBOR )
832
840
833
- const file = new UnixFS ( 'file' )
841
+ const file = new UnixFS ( {
842
+ type : 'file'
843
+ } )
834
844
file . addBlockSize ( 100 )
835
845
836
846
const cid = await ipld . put ( new DAGNode ( file . marshal ( ) , [
@@ -891,4 +901,56 @@ describe('exporter', () => {
891
901
expect ( exported [ 4 ] . name ) . to . equal ( 'qux.txt' )
892
902
expect ( exported [ 4 ] . path ) . to . equal ( `${ dirCid } /qux.txt` )
893
903
} )
904
+
905
+ it ( 'exports a CID encoded with the identity hash' , async ( ) => {
906
+ const data = Buffer . from ( 'hello world' )
907
+ const hash = mh . encode ( data , 'identity' )
908
+ const cid = new CID ( 1 , 'identity' , hash )
909
+
910
+ const exported = await exporter ( cid , ipld )
911
+ const result = Buffer . concat ( await all ( exported . content ( ) ) )
912
+
913
+ expect ( result ) . to . deep . equal ( data )
914
+ expect ( result . toString ( 'utf8' ) ) . to . equal ( 'hello world' )
915
+ } )
916
+
917
+ it ( 'exports a CID encoded with the identity hash with an offset' , async ( ) => {
918
+ const data = Buffer . from ( 'hello world' )
919
+ const hash = mh . encode ( data , 'identity' )
920
+ const cid = new CID ( 1 , 'identity' , hash )
921
+
922
+ const exported = await exporter ( cid , ipld )
923
+ const result = Buffer . concat ( await all ( exported . content ( {
924
+ offset : 1
925
+ } ) ) )
926
+
927
+ expect ( result . toString ( 'utf8' ) ) . to . equal ( 'ello world' )
928
+ } )
929
+
930
+ it ( 'exports a CID encoded with the identity hash with a length' , async ( ) => {
931
+ const data = Buffer . from ( 'hello world' )
932
+ const hash = mh . encode ( data , 'identity' )
933
+ const cid = new CID ( 1 , 'identity' , hash )
934
+
935
+ const exported = await exporter ( cid , ipld )
936
+ const result = Buffer . concat ( await all ( exported . content ( {
937
+ length : 1
938
+ } ) ) )
939
+
940
+ expect ( result . toString ( 'utf8' ) ) . to . equal ( 'h' )
941
+ } )
942
+
943
+ it ( 'exports a CID encoded with the identity hash with an offset and a length' , async ( ) => {
944
+ const data = Buffer . from ( 'hello world' )
945
+ const hash = mh . encode ( data , 'identity' )
946
+ const cid = new CID ( 1 , 'identity' , hash )
947
+
948
+ const exported = await exporter ( cid , ipld )
949
+ const result = Buffer . concat ( await all ( exported . content ( {
950
+ offset : 3 ,
951
+ length : 1
952
+ } ) ) )
953
+
954
+ expect ( result . toString ( 'utf8' ) ) . to . equal ( 'l' )
955
+ } )
894
956
} )
0 commit comments