11var spawn = require ( 'child_process' ) . spawn ;
22var http = require ( 'http' ) ;
33var fs = require ( 'fs' ) ;
4- var options = {
5- host : 's3.chimerajs.com' ,
6- port : 80 ,
7- path : '/qt5_' + process . platform + '_' + process . arch + '.tar.gz'
8- } ;
94var cwd = __dirname + '/../' ;
105
11- http . get ( options , function ( res ) {
12- res . setEncoding ( 'binary' ) ;
13- var fileData = '' ;
14- res . on ( "data" , function ( chunk ) {
15- fileData += chunk ;
6+ function untar ( cb ) {
7+ spawn ( 'tar' , [ 'xf' , 'qt.tar.gz' ] , { cwd : cwd } ) . on ( 'close' , function ( ) {
8+ cb ( ) ;
169 } ) ;
17- res . on ( "end" , function ( ) {
18- fs . writeFile ( cwd + 'qt.tar.gz' , fileData , 'binary' , function ( err ) {
19- if ( err ) throw err
20- console . log ( 'finished downloading, now extracting tar.gz file' ) ;
21- spawn ( 'tar' , [ 'zvxf' , cwd + 'qt.tar.gz' ] , { cwd : cwd } ) . on ( 'close' , function ( ) {
22- console . log ( 'done with extraction' ) ;
23- } ) ;
24- } ) ;
10+ }
11+
12+ function download ( cb ) {
13+ var options = {
14+ host : 's3.chimerajs.com' ,
15+ port : 80 ,
16+ path : '/qt5_' + process . platform + '_' + process . arch + '.tar.gz'
17+ } ;
18+ http . get ( options , function ( res ) {
19+ res . setEncoding ( 'binary' ) ;
20+ var fileData = '' ;
21+ res . on ( "data" , function ( chunk ) {
22+ fileData += chunk ;
23+ } ) ;
24+ res . on ( "end" , function ( ) {
25+ fs . writeFile ( cwd + 'qt.tar.gz' , fileData , 'binary' , function ( err ) {
26+ if ( err ) throw err
27+ console . log ( 'finished downloading, now extracting tar.gz file' ) ;
28+ cb ( ) ;
29+ } ) ;
30+ } ) ;
31+ } ) . on ( 'error' , function ( e ) {
32+ console . log ( "Got error: " + e . message ) ;
2533 } ) ;
26- } ) . on ( 'error' , function ( e ) {
27- console . log ( "Got error: " + e . message ) ;
28- } ) ;
34+ }
35+
36+ fs . exists ( cwd + 'qt.tar.gz' , function ( exists ) {
37+ if ( exists ) {
38+ fs . exists ( cwd + 'qt' , function ( exists ) {
39+ if ( ! exists ) {
40+ untar ( function ( ) {
41+ console . log ( 'done!' ) ;
42+ } ) ;
43+ }
44+ } ) ;
45+ } else {
46+ download ( function ( ) {
47+ untar ( function ( ) {
48+ console . log ( 'done!' ) ;
49+ } ) ;
50+ } ) ;
51+ }
52+ } ) ;
0 commit comments