11
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' )
66
7- var addon = require ( '../build/Release/volume.node' ) ;
7+ var addon = require ( '../build/Release/volume.node' )
88
99var 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
1413
1514 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 )
1917
2018 if ( parentStat . dev !== lastDev ) {
21- return lastPath ;
19+ return lastPath
2220 }
2321
2422 if ( parentStat . ino === lastIno ) {
25- return lastPath ;
23+ return lastPath
2624 }
2725
28- lastDev = parentStat . dev ;
29- lastIno = parentStat . ino ;
30- lastPath = parentPath ;
31-
26+ lastDev = parentStat . dev
27+ lastIno = parentStat . ino
28+ lastPath = parentPath
3229 }
33- } ;
30+ }
3431
3532var utf16be = function ( str ) {
36- var b = new Buffer ( str , 'ucs2' ) ;
33+ var b = new Buffer ( str , 'ucs2' )
3734 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
4138 }
42- return b ;
43- } ;
39+ return b
40+ }
4441
4542module . exports = exports = function ( targetPath ) {
43+ var info = { version : 2 , extra : [ ] }
4644
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 )
4850
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' )
5652
5753 info . target = {
5854 id : targetStat . ino ,
5955 type : ( targetStat . isDirectory ( ) ? 'directory' : 'file' ) ,
6056 filename : path . basename ( targetPath ) ,
6157 created : targetStat . ctime
62- } ;
58+ }
6359
6460 info . parent = {
6561 id : parentStat . ino ,
6662 name : path . basename ( parentPath )
67- } ;
63+ }
6864
6965 info . volume = {
7066 name : addon . getVolumeName ( volumePath ) ,
@@ -73,90 +69,78 @@ module.exports = exports = function (targetPath) {
7369 type : ( volumePath === '/' ? 'local' : 'other' )
7470 } ;
7571
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' )
7974
8075 info . extra . push ( {
8176 type : 0 ,
8277 length : b . length ,
8378 data : b
84- } ) ;
85-
79+ } )
8680 } ( ) ) ;
8781
88- ( function addType1 ( ) {
89-
90- var b = new Buffer ( 4 ) ;
82+ ( function addType1 ( ) {
83+ var b = new Buffer ( 4 )
9184
92- b . writeUInt32BE ( info . parent . id , 0 ) ;
85+ b . writeUInt32BE ( info . parent . id , 0 )
9386
9487 info . extra . push ( {
9588 type : 1 ,
9689 length : b . length ,
9790 data : b
98- } ) ;
99-
91+ } )
10092 } ( ) ) ;
10193
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 ) )
10697
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 )
109100
110101 info . extra . push ( {
111102 type : 14 ,
112103 length : b . length ,
113104 data : b
114- } ) ;
115-
105+ } )
116106 } ( ) ) ;
117107
118- ( function addType15 ( ) {
108+ ( function addType15 ( ) {
109+ var l = info . volume . name . length
110+ var b = new Buffer ( 2 + ( l * 2 ) )
119111
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 )
125114
126115 info . extra . push ( {
127116 type : 15 ,
128117 length : b . length ,
129118 data : b
130- } ) ;
131-
119+ } )
132120 } ( ) ) ;
133121
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' )
140127
141128 info . extra . push ( {
142129 type : 18 ,
143130 length : b . length ,
144131 data : b
145- } ) ;
146-
132+ } )
147133 } ( ) ) ;
148134
149- ( function addType19 ( ) {
150-
151- var b = new Buffer ( volumePath , 'utf8' ) ;
135+ ( function addType19 ( ) {
136+ var b = new Buffer ( volumePath , 'utf8' )
152137
153138 info . extra . push ( {
154139 type : 19 ,
155140 length : b . length ,
156141 data : b
157- } ) ;
158-
159- } ( ) ) ;
142+ } )
143+ } ( ) )
160144
161- return encode ( info ) ;
162- } ;
145+ return encode ( info )
146+ }
0 commit comments