This repository was archived by the owner on Aug 11, 2021. It is now read-only.
File tree 2 files changed +34
-2
lines changed
2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 2
2
const util = require ( './util' )
3
3
4
4
// Immutable block of data
5
- function Block ( data , extension ) {
5
+ function Block ( data , type ) {
6
6
if ( ! data ) {
7
7
throw new Error ( 'Block must be constructed with data' )
8
8
}
@@ -18,7 +18,20 @@ function Block (data, extension) {
18
18
}
19
19
20
20
this . key = util . hash ( this . data )
21
- this . extension = extension || 'data '
21
+ this . type = type || 'protobuf '
22
22
}
23
23
24
+ Object . defineProperty ( Block . prototype , 'extension' , {
25
+ get ( ) {
26
+ switch ( this . type ) {
27
+ case 'protobuf' :
28
+ return 'data'
29
+ case 'ipld' :
30
+ return 'ipld'
31
+ default :
32
+ return this . type
33
+ }
34
+ }
35
+ } )
36
+
24
37
module . exports = Block
Original file line number Diff line number Diff line change @@ -31,4 +31,23 @@ describe('block', () => {
31
31
32
32
expect ( key . equals ( block . key ) ) . to . equal ( false )
33
33
} )
34
+
35
+ it ( 'has the right extension to type mapping' , ( ) => {
36
+ const b1 = new Block ( 'hello' , 'protobuf' )
37
+ const b2 = new Block ( 'hello' )
38
+ const b3 = new Block ( 'hello' , 'ipld' )
39
+ const b4 = new Block ( 'hello' , 'woot' )
40
+
41
+ expect ( b1 . type ) . to . be . eql ( 'protobuf' )
42
+ expect ( b1 . extension ) . to . be . eql ( 'data' )
43
+
44
+ expect ( b2 . type ) . to . be . eql ( 'protobuf' )
45
+ expect ( b2 . extension ) . to . be . eql ( 'data' )
46
+
47
+ expect ( b3 . type ) . to . be . eql ( 'ipld' )
48
+ expect ( b3 . extension ) . to . be . eql ( 'ipld' )
49
+
50
+ expect ( b4 . type ) . to . be . eql ( 'woot' )
51
+ expect ( b4 . extension ) . to . be . eql ( 'woot' )
52
+ } )
34
53
} )
You can’t perform that action at this time.
0 commit comments