@@ -35,9 +35,9 @@ downloader.prototype.writeToDisc = function(options, callback) {
3535
3636 }
3737
38- if ( options . serverDirecotry === undefined ) {
38+ if ( options . serverDirectory === undefined ) {
3939
40- options . serverDirecotry = './downloads' ;
40+ options . serverDirectory = './downloads' ;
4141
4242 }
4343
@@ -46,7 +46,7 @@ downloader.prototype.writeToDisc = function(options, callback) {
4646 var that = this ;
4747
4848 // check if the temporary tracks directory already exists
49- directoryManager . exists ( options . serverDirecotry , function directoryExistsCallback ( error , exists ) {
49+ directoryManager . exists ( options . serverDirectory , function directoryExistsCallback ( error , exists ) {
5050
5151 // if there was no error checking if the directory exists
5252 if ( ! error ) {
@@ -55,7 +55,7 @@ downloader.prototype.writeToDisc = function(options, callback) {
5555 if ( ! exists ) {
5656
5757 // create a new directory
58- directoryManager . create ( options . serverDirecotry , createDirectoryCallback = function ( error ) {
58+ directoryManager . create ( options . serverDirectory , createDirectoryCallback = function ( error ) {
5959
6060 // if there was no error creating the new directory
6161 if ( ! error ) {
@@ -100,7 +100,7 @@ downloader.prototype.downloadIfNotExists = function downloadIfNotExists(options,
100100
101101 var fileManager = new FileManager ( ) ;
102102
103- var filePath = options . serverDirecotry + '/' + options . fileName ;
103+ var filePath = options . serverDirectory + '/' + options . fileName ;
104104
105105 var that = this ;
106106
@@ -141,7 +141,7 @@ downloader.prototype.downloadIfNotExists = function downloadIfNotExists(options,
141141 */
142142downloader . prototype . downloadFile = function downloadFileFunction ( downloadOptions , callback ) {
143143
144- console . log ( 'downloadFile: ' + downloadOptions . path ) ;
144+ console . log ( 'downloadFile: ' + downloadOptions . fileName ) ;
145145
146146 if ( downloadOptions === undefined ) {
147147
@@ -173,18 +173,24 @@ downloader.prototype.downloadFile = function downloadFileFunction(downloadOption
173173
174174 }
175175
176- var writeStream = fs . createWriteStream ( downloadOptions . filePath + downloadOptions . fileName ) ;
176+ // the file path on the server
177+ var serverFilePath = downloadOptions . serverDirectory + '/' + downloadOptions . fileName ;
178+
179+ // create a write stream
180+ var writeStream = fs . createWriteStream ( serverFilePath ) ;
177181
178182 // open a new write stream
179183 writeStream . on ( 'open' , function ( ) {
180184
181185 var requestOptions = {
182186 hostname : downloadOptions . remoteHost ,
183187 port : downloadOptions . remotePort ,
184- path : downloadOptions . remotePath ,
188+ path : downloadOptions . remotePath + downloadOptions . fileName ,
185189 method : downloadOptions . method
186190 } ;
187-
191+
192+ console . log ( requestOptions ) ;
193+
188194 // request the file from remote server
189195 var httpRequest = http . request ( requestOptions , function ( httpResponse ) {
190196
@@ -207,7 +213,7 @@ downloader.prototype.downloadFile = function downloadFileFunction(downloadOption
207213 // close the write stream
208214 writeStream . end ( ) ;
209215
210- callback ( false , downloadOptions . serverDirectory + downloadOptions . fileName ) ;
216+ callback ( false , serverFilePath ) ;
211217
212218 } ) ;
213219
0 commit comments