This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree 4 files changed +42
-5
lines changed
4 files changed +42
-5
lines changed Original file line number Diff line number Diff line change 70
70
"expose-loader" : " ~0.7.5" ,
71
71
"form-data" : " ^2.3.2" ,
72
72
"hat" : " 0.0.3" ,
73
- "interface-ipfs-core" : " ~0.75.2 " ,
73
+ "interface-ipfs-core" : " ~0.76.1 " ,
74
74
"ipfsd-ctl" : " ~0.39.1" ,
75
75
"mocha" : " ^5.2.0" ,
76
76
"ncp" : " ^2.0.0" ,
105
105
"hoek" : " ^5.0.3" ,
106
106
"human-to-milliseconds" : " ^1.0.0" ,
107
107
"interface-datastore" : " ~0.4.2" ,
108
- "ipfs-api" : " ^22.2.4 " ,
108
+ "ipfs-api" : " ^24.0.0 " ,
109
109
"ipfs-bitswap" : " ~0.20.3" ,
110
110
"ipfs-block" : " ~0.7.1" ,
111
111
"ipfs-block-service" : " ~0.14.0" ,
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,34 @@ describe('object', () => runOnAndOff((thing) => {
41
41
} )
42
42
} )
43
43
44
+ it ( 'get with data' , function ( ) {
45
+ this . timeout ( 15 * 1000 )
46
+
47
+ return ipfs ( 'object new' )
48
+ . then ( ( out ) => out . trim ( ) )
49
+ . then ( ( hash ) => ipfs ( `object patch set-data ${ hash } test/fixtures/test-data/hello` ) )
50
+ . then ( ( out ) => out . trim ( ) )
51
+ . then ( ( hash ) => ipfs ( `object get ${ hash } ` ) )
52
+ . then ( ( out ) => {
53
+ const result = JSON . parse ( out )
54
+ expect ( result . Data ) . to . eql ( 'aGVsbG8gd29ybGQK' )
55
+ } )
56
+ } )
57
+
58
+ it ( 'get while overriding data-encoding' , function ( ) {
59
+ this . timeout ( 15 * 1000 )
60
+
61
+ return ipfs ( 'object new' )
62
+ . then ( ( out ) => out . trim ( ) )
63
+ . then ( ( hash ) => ipfs ( `object patch set-data ${ hash } test/fixtures/test-data/hello` ) )
64
+ . then ( ( out ) => out . trim ( ) )
65
+ . then ( ( hash ) => ipfs ( `object get --data-encoding=utf8 ${ hash } ` ) )
66
+ . then ( ( out ) => {
67
+ const result = JSON . parse ( out )
68
+ expect ( result . Data ) . to . eql ( 'hello world\n' )
69
+ } )
70
+ } )
71
+
44
72
it ( 'put' , ( ) => {
45
73
return ipfs ( 'object put test/fixtures/test-data/node.json' ) . then ( ( out ) => {
46
74
expect ( out ) . to . eql (
You can’t perform that action at this time.
0 commit comments