@@ -47,11 +47,10 @@ describe('dag', () => {
47
47
}
48
48
49
49
ipfs . dag . get . withArgs ( rawCid , defaultOptions ) . returns ( result )
50
- ipfs . bases . getBase . withArgs ( 'base58btc' ) . returns ( base58btc )
51
50
52
- const out = await cli ( `dag get ${ rawCid } --data-enc base16` , { ipfs } )
51
+ const out = await cli ( `dag get ${ rawCid } --output-codec raw -- data-enc base16` , { ipfs } )
53
52
54
- expect ( out ) . to . equal ( uint8ArrayToString ( result . value , 'base16' ) + '\n' )
53
+ expect ( out ) . to . equal ( uint8ArrayToString ( result . value , 'base16' ) )
55
54
} )
56
55
57
56
it ( 'should get a dag-pb node' , async ( ) => {
@@ -67,14 +66,13 @@ describe('dag', () => {
67
66
}
68
67
69
68
ipfs . dag . get . withArgs ( dagPbCid , defaultOptions ) . returns ( result )
70
- ipfs . bases . getBase . withArgs ( 'base58btc' ) . returns ( base58btc )
71
69
72
70
const out = await cli ( `dag get ${ dagPbCid } ` , { ipfs } )
73
71
74
- expect ( out ) . to . equal ( `{"data":"AAED","links":[{"Name ":"foo","Size":10,"Cid ":{"/":"${ dagCborCid . toString ( base58btc ) } "}}]}\n ` )
72
+ expect ( out ) . to . equal ( `{"Data":{"/":{"bytes ":"AAED"}},"Links":[{"Hash ":{"/":"${ dagCborCid . toString ( ) } "},"Name":"foo","Tsize":10 }]}` )
75
73
} )
76
74
77
- it ( 'should get a dag-pb node and specify data encoding ' , async ( ) => {
75
+ it ( 'should get a dag-pb node as dag-pb ' , async ( ) => {
78
76
const result = {
79
77
value : {
80
78
Data : Buffer . from ( [ 0 , 1 , 3 ] ) ,
@@ -87,14 +85,13 @@ describe('dag', () => {
87
85
}
88
86
89
87
ipfs . dag . get . withArgs ( dagPbCid , defaultOptions ) . returns ( result )
90
- ipfs . bases . getBase . withArgs ( 'base58btc' ) . returns ( base58btc )
91
88
92
- const out = await cli ( `dag get ${ dagPbCid } --data-enc base16 ` , { ipfs } )
89
+ const out = await cli ( `dag get ${ dagPbCid } --output-codec dag-pb ` , { ipfs, raw : true } )
93
90
94
- expect ( out ) . to . equal ( `{"data":"000103","links":[{"Name":"foo","Size":10,"Cid":{"/":" ${ dagCborCid . toString ( base58btc ) } "}}]}\n` )
91
+ expect ( out ) . to . deep . equal ( Buffer . from ( '122d0a2401711220b80784f97f67ad80d52575d643044ffb37b20f8d4db32ae59e47b1ac68df20e01203666f6f180a0a03000103' , 'hex' ) )
95
92
} )
96
93
97
- it ( 'should get a dag-pb node and specify CID encoding ' , async ( ) => {
94
+ it ( 'should get a dag-pb node as dag-cbor ' , async ( ) => {
98
95
const result = {
99
96
value : {
100
97
Data : Buffer . from ( [ 0 , 1 , 3 ] ) ,
@@ -107,11 +104,55 @@ describe('dag', () => {
107
104
}
108
105
109
106
ipfs . dag . get . withArgs ( dagPbCid , defaultOptions ) . returns ( result )
110
- ipfs . bases . getBase . withArgs ( 'base64' ) . returns ( base64 )
111
107
112
- const out = await cli ( `dag get ${ dagPbCid } --cid-base base64` , { ipfs } )
108
+ const out = await cli ( `dag get ${ dagPbCid } --output-codec dag-cbor` , { ipfs, raw : true } )
109
+
110
+ expect ( out ) . to . deep . equal ( Buffer . from ( 'a2644461746143000103654c696e6b7381a36448617368d82a58250001711220b80784f97f67ad80d52575d643044ffb37b20f8d4db32ae59e47b1ac68df20e0644e616d6563666f6f655473697a650a' , 'hex' ) )
111
+ } )
112
+
113
+ it ( 'should fail to get a non bytes node with "raw"' , async ( ) => {
114
+ const result = {
115
+ value : {
116
+ Data : Buffer . from ( [ 0 , 1 , 3 ] ) ,
117
+ Links : [ {
118
+ Hash : dagCborCid ,
119
+ Name : 'foo' ,
120
+ Tsize : 10
121
+ } ]
122
+ }
123
+ }
124
+
125
+ ipfs . dag . get . withArgs ( dagPbCid , defaultOptions ) . returns ( result )
126
+
127
+ const out = await cli ( `dag get ${ dagPbCid } --output-codec raw --data-enc base16` , { ipfs } )
113
128
114
- expect ( out ) . to . equal ( `{"data":"AAED","links":[{"Name":"foo","Size":10,"Cid":{"/":"${ dagCborCid . toString ( base64 ) } "}}]}\n` )
129
+ expect ( out ) . to . equal ( 'dag get cannot print a non-bytes node as "raw"\n' )
130
+ } )
131
+
132
+ it ( 'should get a bytes node of a non-bytes block with "raw"' , async ( ) => {
133
+ // in this instance we're pretending to path into a 'Data' property of a dag-pb block
134
+ const result = {
135
+ value : Buffer . from ( [ 0 , 1 , 3 ] )
136
+ }
137
+
138
+ ipfs . dag . get . withArgs ( dagPbCid , { ...defaultOptions , path : '/Data' } ) . returns ( result )
139
+
140
+ const out = await cli ( `dag get ${ dagPbCid } /Data --output-codec raw --data-enc base16` , { ipfs } )
141
+
142
+ expect ( out ) . to . equal ( '000103' )
143
+ } )
144
+
145
+ it ( 'should get raw bytes without data encoding' , async ( ) => {
146
+ // in this instance we're pretending to path into a 'Data' property of a dag-pb block
147
+ const result = {
148
+ value : Buffer . from ( [ 0 , 1 , 3 ] )
149
+ }
150
+
151
+ ipfs . dag . get . withArgs ( rawCid , defaultOptions ) . returns ( result )
152
+
153
+ const out = await cli ( `dag get ${ rawCid } --output-codec raw` , { ipfs } )
154
+
155
+ expect ( out ) . to . equal ( Buffer . from ( [ 0 , 1 , 3 ] ) . toString ( ) )
115
156
} )
116
157
117
158
it ( 'should get a dag-cbor node' , async ( ) => {
@@ -122,43 +163,39 @@ describe('dag', () => {
122
163
}
123
164
124
165
ipfs . dag . get . withArgs ( dagCborCid , defaultOptions ) . returns ( result )
125
- ipfs . bases . getBase . withArgs ( 'base58btc' ) . returns ( base58btc )
126
166
127
167
const out = await cli ( `dag get ${ dagCborCid } ` , { ipfs } )
128
168
129
- expect ( out ) . to . equal ( '{"foo":"bar"}\n ' )
169
+ expect ( out ) . to . equal ( '{"foo":"bar"}' )
130
170
} )
131
171
132
- it ( 'should get a dag-cbor node with a nested CID ' , async ( ) => {
172
+ it ( 'should get a dag-cbor node as dag-cbor ' , async ( ) => {
133
173
const result = {
134
174
value : {
135
- foo : 'bar' ,
136
- baz : dagPbCid
175
+ foo : 'bar'
137
176
}
138
177
}
139
178
140
179
ipfs . dag . get . withArgs ( dagCborCid , defaultOptions ) . returns ( result )
141
- ipfs . bases . getBase . withArgs ( 'base58btc' ) . returns ( base58btc )
142
180
143
- const out = await cli ( `dag get ${ dagCborCid } ` , { ipfs } )
181
+ const out = await cli ( `dag get ${ dagCborCid } --output-codec dag-cbor ` , { ipfs, raw : true } )
144
182
145
- expect ( out ) . to . equal ( `{"foo":"bar","baz":{"/":" ${ dagPbCid } "}}\n` )
183
+ expect ( out ) . to . deep . equal ( Buffer . from ( 'a163666f6f63626172' , 'hex' ) )
146
184
} )
147
185
148
- it ( 'should get a dag-cbor node with a nested CID and change the encoding ' , async ( ) => {
186
+ it ( 'should get a dag-cbor node with a nested CID' , async ( ) => {
149
187
const result = {
150
188
value : {
151
189
foo : 'bar' ,
152
- baz : rawCid
190
+ baz : dagPbCid
153
191
}
154
192
}
155
193
156
194
ipfs . dag . get . withArgs ( dagCborCid , defaultOptions ) . returns ( result )
157
- ipfs . bases . getBase . withArgs ( 'base64' ) . returns ( base64 )
158
195
159
- const out = await cli ( `dag get ${ dagCborCid } --cid-base=base64 ` , { ipfs } )
196
+ const out = await cli ( `dag get ${ dagCborCid } ` , { ipfs } )
160
197
161
- expect ( out ) . to . equal ( `{"foo":"bar"," baz":{"/":"${ rawCid . toString ( base64 ) } "}}\n ` )
198
+ expect ( out ) . to . equal ( `{"baz":{"/":"${ dagPbCid } "},"foo":"bar"} ` )
162
199
} )
163
200
164
201
it ( 'should get a node with a deep path' , async ( ) => {
@@ -172,9 +209,9 @@ describe('dag', () => {
172
209
path
173
210
} ) . returns ( result )
174
211
175
- const out = await cli ( `dag get ${ rawCid } ${ path } --data-enc base16` , { ipfs } )
212
+ const out = await cli ( `dag get ${ rawCid } ${ path } --output-codec raw -- data-enc base16` , { ipfs } )
176
213
177
- expect ( out ) . to . be . eql ( uint8ArrayToString ( result . value , 'base16' ) + '\n' )
214
+ expect ( out ) . to . be . eql ( uint8ArrayToString ( result . value , 'base16' ) )
178
215
} )
179
216
180
217
it ( 'should get a node with a deep path and an ipfs prefix' , async ( ) => {
@@ -188,9 +225,9 @@ describe('dag', () => {
188
225
path
189
226
} ) . returns ( result )
190
227
191
- const out = await cli ( `dag get /ipfs/${ rawCid } ${ path } --data-enc base16` , { ipfs } )
228
+ const out = await cli ( `dag get /ipfs/${ rawCid } ${ path } --output-codec raw -- data-enc base16` , { ipfs } )
192
229
193
- expect ( out ) . to . be . eql ( uint8ArrayToString ( result . value , 'base16' ) + '\n' )
230
+ expect ( out ) . to . be . eql ( uint8ArrayToString ( result . value , 'base16' ) )
194
231
} )
195
232
196
233
it ( 'should get a node with local resolve' , async ( ) => {
@@ -203,11 +240,11 @@ describe('dag', () => {
203
240
localResolve : true
204
241
} ) . returns ( result )
205
242
206
- const out = await cli ( `dag get ${ rawCid } --local-resolve --data-enc base16` , { ipfs } )
243
+ const out = await cli ( `dag get ${ rawCid } --local-resolve --output-codec raw -- data-enc base16` , { ipfs } )
207
244
208
245
expect ( out ) . to . include ( 'resolving path within the node only\n' )
209
246
expect ( out ) . to . include ( 'remainder path: n/a\n' )
210
- expect ( out ) . to . include ( uint8ArrayToString ( result . value , 'base16' ) + '\n' )
247
+ expect ( out ) . to . include ( uint8ArrayToString ( result . value , 'base16' ) )
211
248
} )
212
249
213
250
it ( 'should get a node with a timeout' , async ( ) => {
@@ -220,9 +257,9 @@ describe('dag', () => {
220
257
timeout : 1000
221
258
} ) . returns ( result )
222
259
223
- const out = await cli ( `dag get ${ rawCid } --timeout=1s --data-enc base16` , { ipfs } )
260
+ const out = await cli ( `dag get ${ rawCid } --timeout=1s --output-codec raw -- data-enc base16` , { ipfs } )
224
261
225
- expect ( out ) . to . be . eql ( uint8ArrayToString ( result . value , 'base16' ) + '\n' )
262
+ expect ( out ) . to . be . eql ( uint8ArrayToString ( result . value , 'base16' ) )
226
263
} )
227
264
228
265
it ( 'should strip control characters from dag-pb nodes' , async ( ) => {
@@ -237,14 +274,13 @@ describe('dag', () => {
237
274
}
238
275
239
276
ipfs . dag . get . withArgs ( dagPbCid , defaultOptions ) . returns ( result )
240
- ipfs . bases . getBase . withArgs ( 'base58btc' ) . returns ( base58btc )
241
277
242
278
const out = await cli ( `dag get ${ dagPbCid } ` , { ipfs } )
243
279
244
- expect ( out ) . to . equal ( `{"links ":[{"Name":"foo.txt","Size":9000,"Cid": {"/":"${ dagPbCid . toString ( base58btc ) } "}}]}\n ` )
280
+ expect ( out ) . to . equal ( `{"Links ":[{"Hash": {"/":"${ dagPbCid . toString ( base58btc ) } "},"Name":"foo\\b\\n\\t.txt","Tsize":9000 }]}` )
245
281
} )
246
282
247
- it ( 'should strip control characters from dag-cbor nodes' , async ( ) => {
283
+ it ( 'should not strip control characters from dag-cbor nodes' , async ( ) => {
248
284
const result = {
249
285
value : {
250
286
'lo\nl' : 'ok\t'
@@ -255,10 +291,10 @@ describe('dag', () => {
255
291
256
292
const out = await cli ( `dag get ${ dagCborCid } ` , { ipfs } )
257
293
258
- expect ( out ) . to . equal ( '{"lol ":"ok"}\n ' )
294
+ expect ( out ) . to . equal ( '{"lo\\nl ":"ok\\t"} ' )
259
295
} )
260
296
261
- it ( 'should strip control characters from dag-cbor string nodes' , async ( ) => {
297
+ it ( 'should not strip control characters from dag-cbor string nodes' , async ( ) => {
262
298
const result = {
263
299
value : 'lo\nl'
264
300
}
@@ -267,10 +303,10 @@ describe('dag', () => {
267
303
268
304
const out = await cli ( `dag get ${ dagCborCid } ` , { ipfs } )
269
305
270
- expect ( out ) . to . equal ( '"lol"\n ' )
306
+ expect ( out ) . to . equal ( '"lo\\nl" ' )
271
307
} )
272
308
273
- it ( 'should strip control characters from dag-cbor array nodes' , async ( ) => {
309
+ it ( 'should not strip control characters from dag-cbor array nodes' , async ( ) => {
274
310
const result = {
275
311
value : [ 'lo\nl' ]
276
312
}
@@ -279,10 +315,10 @@ describe('dag', () => {
279
315
280
316
const out = await cli ( `dag get ${ dagCborCid } ` , { ipfs } )
281
317
282
- expect ( out ) . to . equal ( '["lol"]\n ' )
318
+ expect ( out ) . to . equal ( '["lo\\nl"] ' )
283
319
} )
284
320
285
- it ( 'should strip control characters from dag-cbor nested array nodes' , async ( ) => {
321
+ it ( 'should not strip control characters from dag-cbor nested array nodes' , async ( ) => {
286
322
const result = {
287
323
value : {
288
324
'lo\nl' : [ 'ok\t' ]
@@ -293,7 +329,7 @@ describe('dag', () => {
293
329
294
330
const out = await cli ( `dag get ${ dagCborCid } ` , { ipfs } )
295
331
296
- expect ( out ) . to . equal ( '{"lol ":["ok"]}\n ' )
332
+ expect ( out ) . to . equal ( '{"lo\\nl ":["ok\\t "]}' )
297
333
} )
298
334
} )
299
335
0 commit comments