This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree 3 files changed +36
-3
lines changed
3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,12 @@ module.exports = {
7
7
8
8
describe : 'Get and serialize the DAG node named by <key>' ,
9
9
10
- builder : { } ,
10
+ builder : {
11
+ 'data-encoding' : {
12
+ type : 'string' ,
13
+ default : 'base64'
14
+ }
15
+ } ,
11
16
12
17
handler ( argv ) {
13
18
argv . ipfs . object . get ( argv . key , { enc : 'base58' } , ( err , node ) => {
@@ -16,7 +21,9 @@ module.exports = {
16
21
}
17
22
const nodeJSON = node . toJSON ( )
18
23
19
- nodeJSON . data = nodeJSON . data ? nodeJSON . data . toString ( ) : ''
24
+ if ( Buffer . isBuffer ( node . data ) ) {
25
+ nodeJSON . data = node . data . toString ( argv [ 'data-encoding' ] || undefined )
26
+ }
20
27
21
28
const answer = {
22
29
Data : nodeJSON . data ,
Original file line number Diff line number Diff line change @@ -85,7 +85,9 @@ exports.get = {
85
85
86
86
const nodeJSON = node . toJSON ( )
87
87
88
- nodeJSON . data = nodeJSON . data ? nodeJSON . data . toString ( ) : ''
88
+ if ( Buffer . isBuffer ( node . data ) ) {
89
+ nodeJSON . data = node . data . toString ( request . query [ 'data-encoding' ] || undefined )
90
+ }
89
91
90
92
const answer = {
91
93
Data : nodeJSON . data ,
Original file line number Diff line number Diff line change @@ -41,6 +41,30 @@ describe('object', () => runOnAndOff((thing) => {
41
41
} )
42
42
} )
43
43
44
+ it ( 'get with data' , ( ) => {
45
+ return ipfs ( 'object new' )
46
+ . then ( ( out ) => out . trim ( ) )
47
+ . then ( ( hash ) => ipfs ( `object patch set-data ${ hash } test/fixtures/test-data/hello` ) )
48
+ . then ( ( out ) => out . trim ( ) )
49
+ . then ( ( hash ) => ipfs ( `object get ${ hash } ` ) )
50
+ . then ( ( out ) => {
51
+ const result = JSON . parse ( out )
52
+ expect ( result . Data ) . to . eql ( 'aGVsbG8gd29ybGQK' )
53
+ } )
54
+ } )
55
+
56
+ it ( 'get while overriding data-encoding' , ( ) => {
57
+ return ipfs ( 'object new' )
58
+ . then ( ( out ) => out . trim ( ) )
59
+ . then ( ( hash ) => ipfs ( `object patch set-data ${ hash } test/fixtures/test-data/hello` ) )
60
+ . then ( ( out ) => out . trim ( ) )
61
+ . then ( ( hash ) => ipfs ( `object get --data-encoding=utf8 ${ hash } ` ) )
62
+ . then ( ( out ) => {
63
+ const result = JSON . parse ( out )
64
+ expect ( result . Data ) . to . eql ( 'hello world\n' )
65
+ } )
66
+ } )
67
+
44
68
it ( 'put' , ( ) => {
45
69
return ipfs ( 'object put test/fixtures/test-data/node.json' ) . then ( ( out ) => {
46
70
expect ( out ) . to . eql (
You can’t perform that action at this time.
0 commit comments