1
1
2
- var fs = require ( 'fs' ) ;
3
- var path = require ( 'path' ) ;
4
- var assert = require ( 'assert' ) ;
5
- var encode = require ( './encode' ) ;
2
+ var fs = require ( 'fs' )
3
+ var path = require ( 'path' )
4
+ var assert = require ( 'assert' )
5
+ var encode = require ( './encode' )
6
6
7
- var addon = require ( '../build/Release/volume.node' ) ;
7
+ var addon = require ( '../build/Release/volume.node' )
8
8
9
9
var findVolume = function ( startPath , startStat ) {
10
-
11
- var lastDev = startStat . dev ;
12
- var lastIno = startStat . ino ;
13
- var lastPath = startPath ;
10
+ var lastDev = startStat . dev
11
+ var lastIno = startStat . ino
12
+ var lastPath = startPath
14
13
15
14
while ( 1 ) {
16
-
17
- var parentPath = path . resolve ( lastPath , '..' ) ;
18
- var parentStat = fs . statSync ( parentPath ) ;
15
+ var parentPath = path . resolve ( lastPath , '..' )
16
+ var parentStat = fs . statSync ( parentPath )
19
17
20
18
if ( parentStat . dev !== lastDev ) {
21
- return lastPath ;
19
+ return lastPath
22
20
}
23
21
24
22
if ( parentStat . ino === lastIno ) {
25
- return lastPath ;
23
+ return lastPath
26
24
}
27
25
28
- lastDev = parentStat . dev ;
29
- lastIno = parentStat . ino ;
30
- lastPath = parentPath ;
31
-
26
+ lastDev = parentStat . dev
27
+ lastIno = parentStat . ino
28
+ lastPath = parentPath
32
29
}
33
- } ;
30
+ }
34
31
35
32
var utf16be = function ( str ) {
36
- var b = new Buffer ( str , 'ucs2' ) ;
33
+ var b = new Buffer ( str , 'ucs2' )
37
34
for ( var i = 0 ; i < b . length ; i += 2 ) {
38
- var a = b [ i ] ;
39
- b [ i ] = b [ i + 1 ] ;
40
- b [ i + 1 ] = a ;
35
+ var a = b [ i ]
36
+ b [ i ] = b [ i + 1 ]
37
+ b [ i + 1 ] = a
41
38
}
42
- return b ;
43
- } ;
39
+ return b
40
+ }
44
41
45
42
module . exports = exports = function ( targetPath ) {
43
+ var info = { version : 2 , extra : [ ] }
46
44
47
- var info = { version : 2 , extra : [ ] } ;
45
+ var parentPath = path . resolve ( targetPath , '..' )
46
+ var targetStat = fs . statSync ( targetPath )
47
+ var parentStat = fs . statSync ( parentPath )
48
+ var volumePath = findVolume ( targetPath , targetStat )
49
+ var volumeStat = fs . statSync ( volumePath )
48
50
49
- var parentPath = path . resolve ( targetPath , '..' ) ;
50
- var targetStat = fs . statSync ( targetPath ) ;
51
- var parentStat = fs . statSync ( parentPath ) ;
52
- var volumePath = findVolume ( targetPath , targetStat ) ;
53
- var volumeStat = fs . statSync ( volumePath ) ;
54
-
55
- assert ( targetStat . isFile ( ) || targetStat . isDirectory ( ) , 'Target is a file or directory' ) ;
51
+ assert ( targetStat . isFile ( ) || targetStat . isDirectory ( ) , 'Target is a file or directory' )
56
52
57
53
info . target = {
58
54
id : targetStat . ino ,
59
55
type : ( targetStat . isDirectory ( ) ? 'directory' : 'file' ) ,
60
56
filename : path . basename ( targetPath ) ,
61
57
created : targetStat . ctime
62
- } ;
58
+ }
63
59
64
60
info . parent = {
65
61
id : parentStat . ino ,
66
62
name : path . basename ( parentPath )
67
- } ;
63
+ }
68
64
69
65
info . volume = {
70
66
name : addon . getVolumeName ( volumePath ) ,
@@ -73,90 +69,78 @@ module.exports = exports = function (targetPath) {
73
69
type : ( volumePath === '/' ? 'local' : 'other' )
74
70
} ;
75
71
76
- ( function addType0 ( ) {
77
-
78
- var b = new Buffer ( info . parent . name , 'utf8' ) ;
72
+ ( function addType0 ( ) {
73
+ var b = new Buffer ( info . parent . name , 'utf8' )
79
74
80
75
info . extra . push ( {
81
76
type : 0 ,
82
77
length : b . length ,
83
78
data : b
84
- } ) ;
85
-
79
+ } )
86
80
} ( ) ) ;
87
81
88
- ( function addType1 ( ) {
89
-
90
- var b = new Buffer ( 4 ) ;
82
+ ( function addType1 ( ) {
83
+ var b = new Buffer ( 4 )
91
84
92
- b . writeUInt32BE ( info . parent . id , 0 ) ;
85
+ b . writeUInt32BE ( info . parent . id , 0 )
93
86
94
87
info . extra . push ( {
95
88
type : 1 ,
96
89
length : b . length ,
97
90
data : b
98
- } ) ;
99
-
91
+ } )
100
92
} ( ) ) ;
101
93
102
- ( function addType14 ( ) {
103
-
104
- var l = info . target . filename . length ;
105
- var b = new Buffer ( 2 + ( l * 2 ) ) ;
94
+ ( function addType14 ( ) {
95
+ var l = info . target . filename . length
96
+ var b = new Buffer ( 2 + ( l * 2 ) )
106
97
107
- b . writeUInt16BE ( l , 0 ) ;
108
- utf16be ( info . target . filename ) . copy ( b , 2 ) ;
98
+ b . writeUInt16BE ( l , 0 )
99
+ utf16be ( info . target . filename ) . copy ( b , 2 )
109
100
110
101
info . extra . push ( {
111
102
type : 14 ,
112
103
length : b . length ,
113
104
data : b
114
- } ) ;
115
-
105
+ } )
116
106
} ( ) ) ;
117
107
118
- ( function addType15 ( ) {
108
+ ( function addType15 ( ) {
109
+ var l = info . volume . name . length
110
+ var b = new Buffer ( 2 + ( l * 2 ) )
119
111
120
- var l = info . volume . name . length ;
121
- var b = new Buffer ( 2 + ( l * 2 ) ) ;
122
-
123
- b . writeUInt16BE ( l , 0 ) ;
124
- utf16be ( info . volume . name ) . copy ( b , 2 ) ;
112
+ b . writeUInt16BE ( l , 0 )
113
+ utf16be ( info . volume . name ) . copy ( b , 2 )
125
114
126
115
info . extra . push ( {
127
116
type : 15 ,
128
117
length : b . length ,
129
118
data : b
130
- } ) ;
131
-
119
+ } )
132
120
} ( ) ) ;
133
121
134
- ( function addType18 ( ) {
135
-
136
- var vl = volumePath . length ;
137
- assert . equal ( targetPath . slice ( 0 , vl ) , volumePath ) ;
138
- var lp = targetPath . slice ( vl ) ;
139
- var b = new Buffer ( lp , 'utf8' ) ;
122
+ ( function addType18 ( ) {
123
+ var vl = volumePath . length
124
+ assert . equal ( targetPath . slice ( 0 , vl ) , volumePath )
125
+ var lp = targetPath . slice ( vl )
126
+ var b = new Buffer ( lp , 'utf8' )
140
127
141
128
info . extra . push ( {
142
129
type : 18 ,
143
130
length : b . length ,
144
131
data : b
145
- } ) ;
146
-
132
+ } )
147
133
} ( ) ) ;
148
134
149
- ( function addType19 ( ) {
150
-
151
- var b = new Buffer ( volumePath , 'utf8' ) ;
135
+ ( function addType19 ( ) {
136
+ var b = new Buffer ( volumePath , 'utf8' )
152
137
153
138
info . extra . push ( {
154
139
type : 19 ,
155
140
length : b . length ,
156
141
data : b
157
- } ) ;
158
-
159
- } ( ) ) ;
142
+ } )
143
+ } ( ) )
160
144
161
- return encode ( info ) ;
162
- } ;
145
+ return encode ( info )
146
+ }
0 commit comments