@@ -4,8 +4,9 @@ const PREFIX_LENGTH = 8
4
4
5
5
exports = module . exports
6
6
7
- function multihashToPath ( multihash ) {
8
- const filename = multihash . toString ( 'hex' ) + '.data'
7
+ function multihashToPath ( multihash , extension ) {
8
+ extension = extension || 'data'
9
+ const filename = `${ multihash . toString ( 'hex' ) } .${ extension } `
9
10
const folder = filename . slice ( 0 , PREFIX_LENGTH )
10
11
const path = folder + '/' + filename
11
12
@@ -16,21 +17,36 @@ exports.setUp = (basePath, blobStore, locks) => {
16
17
const store = blobStore ( basePath + '/blocks' )
17
18
18
19
return {
19
- createReadStream : ( multihash ) => {
20
- const path = multihashToPath ( multihash )
20
+ createReadStream : ( multihash , extension ) => {
21
+ const path = multihashToPath ( multihash , extension )
21
22
return store . createReadStream ( path )
22
23
} ,
23
24
24
- createWriteStream : ( multihash , cb ) => {
25
- const path = multihashToPath ( multihash )
25
+ createWriteStream : ( multihash , extension , cb ) => {
26
+ if ( typeof extension === 'function' ) {
27
+ cb = extension
28
+ extension = undefined
29
+ }
30
+
31
+ const path = multihashToPath ( multihash , extension )
26
32
return store . createWriteStream ( path , cb )
27
33
} ,
28
- exists : ( multihash , cb ) => {
29
- const path = multihashToPath ( multihash )
34
+ exists : ( multihash , extension , cb ) => {
35
+ if ( typeof extension === 'function' ) {
36
+ cb = extension
37
+ extension = undefined
38
+ }
39
+
40
+ const path = multihashToPath ( multihash , extension )
30
41
return store . exists ( path , cb )
31
42
} ,
32
- remove : ( multihash , cb ) => {
33
- const path = multihashToPath ( multihash )
43
+ remove : ( multihash , extension , cb ) => {
44
+ if ( typeof extension === 'function' ) {
45
+ cb = extension
46
+ extension = undefined
47
+ }
48
+
49
+ const path = multihashToPath ( multihash , extension )
34
50
return store . remove ( path , cb )
35
51
}
36
52
}
0 commit comments