1
- 'use strict'
2
-
3
- const isStream = require ( 'is-stream' )
4
- const promisify = require ( 'promisify-es6' )
5
- const ProgressStream = require ( '../utils/progress-stream' )
6
- const converter = require ( '../utils/converter' )
7
-
8
- module . exports = ( send ) => {
9
- return promisify ( ( files , opts , callback ) => {
10
- if ( typeof opts === 'function' ) {
11
- callback = opts
12
- opts = { }
1
+ const isStream = require ( "is-stream" ) ;
2
+ const promisify = require ( "promisify-es6" ) ;
3
+ const ProgressStream = require ( "../utils/progress-stream" ) ;
4
+ const converter = require ( "../utils/converter" ) ;
5
+
6
+ module . exports = send =>
7
+ promisify ( ( files , opts , callback ) => {
8
+ if ( typeof opts === "function" ) {
9
+ callback = opts ;
10
+ opts = { } ;
13
11
}
14
12
15
- opts = opts || { }
13
+ opts = opts || { } ;
16
14
17
- const ok = Buffer . isBuffer ( files ) ||
18
- isStream . readable ( files ) ||
19
- Array . isArray ( files )
15
+ const ok =
16
+ Buffer . isBuffer ( files ) ||
17
+ isStream . readable ( files ) ||
18
+ Array . isArray ( files ) ;
20
19
21
20
if ( ! ok ) {
22
- return callback ( new Error ( '"files" must be a buffer, readable stream, or array of objects' ) )
21
+ return callback (
22
+ new Error (
23
+ '"files" must be a buffer, readable stream, or array of objects'
24
+ )
25
+ ) ;
23
26
}
24
27
25
- const qs = { }
28
+ const qs = { } ;
26
29
27
- if ( opts [ ' cid-version' ] != null ) {
28
- qs [ ' cid-version' ] = opts [ ' cid-version' ]
30
+ if ( opts [ " cid-version" ] != null ) {
31
+ qs [ " cid-version" ] = opts [ " cid-version" ] ;
29
32
} else if ( opts . cidVersion != null ) {
30
- qs [ ' cid-version' ] = opts . cidVersion
33
+ qs [ " cid-version" ] = opts . cidVersion ;
31
34
}
32
35
33
- if ( opts [ ' raw-leaves' ] != null ) {
34
- qs [ ' raw-leaves' ] = opts [ ' raw-leaves' ]
36
+ if ( opts [ " raw-leaves" ] != null ) {
37
+ qs [ " raw-leaves" ] = opts [ " raw-leaves" ] ;
35
38
} else if ( opts . rawLeaves != null ) {
36
- qs [ ' raw-leaves' ] = opts . rawLeaves
39
+ qs [ " raw-leaves" ] = opts . rawLeaves ;
37
40
}
38
41
39
42
if ( opts . hash != null ) {
40
- qs . hash = opts . hash
43
+ qs . hash = opts . hash ;
41
44
} else if ( opts . hashAlg != null ) {
42
- qs . hash = opts . hashAlg
45
+ qs . hash = opts . hashAlg ;
43
46
}
44
47
if ( opts [ "only-hash" ] != null ) {
45
48
qs [ "only-hash" ] = opts [ "only-hash" ] ;
@@ -48,10 +51,18 @@ module.exports = (send) => {
48
51
qs . pin = opts . pin ;
49
52
}
50
53
51
- const request = { path : 'add' , files : files , qs : qs , progress : opts . progress }
54
+ const request = {
55
+ path : "add" ,
56
+ files,
57
+ qs,
58
+ progress : opts . progress
59
+ } ;
52
60
53
- send . andTransform ( request , ( response , cb ) => {
54
- converter ( ProgressStream . fromStream ( opts . progress , response ) , cb )
55
- } , callback )
56
- } )
57
- }
61
+ send . andTransform (
62
+ request ,
63
+ ( response , cb ) => {
64
+ converter ( ProgressStream . fromStream ( opts . progress , response ) , cb ) ;
65
+ } ,
66
+ callback
67
+ ) ;
68
+ } ) ;
0 commit comments