nodejs-file-downloader
Advanced tools
Comparing version 4.11.2 to 4.12.0
@@ -0,1 +1,6 @@ | ||
## 4.12.0 23/05/2023 | ||
### Added | ||
- Added "method" option to config | ||
## 4.11.1 16/04/2023 | ||
@@ -2,0 +7,0 @@ |
@@ -31,2 +31,3 @@ const fs = require('fs'); | ||
* @param {string} config.url | ||
* @param {string} [config.method = 'GET'] | ||
* @param {string} [config.directory] | ||
@@ -61,3 +62,4 @@ * @param {string} [config.fileName = undefined] | ||
onBeforeSave: undefined, | ||
onProgress: undefined | ||
onProgress: undefined, | ||
method: 'GET', | ||
} | ||
@@ -297,6 +299,7 @@ | ||
async _makeRequest() { | ||
const { timeout, headers, proxy, url, httpsAgent } = this.config; | ||
const { timeout, headers, proxy, url, httpsAgent,method } = this.config; | ||
const options = { | ||
timeout, | ||
headers | ||
headers, | ||
method | ||
} | ||
@@ -303,0 +306,0 @@ if (httpsAgent) { |
@@ -53,2 +53,3 @@ const rpur = require('./utils/rpur') | ||
* @param {string} config.url | ||
* @param {string} [config.method= 'GET'] | ||
* @param {string} [config.directory] | ||
@@ -93,3 +94,4 @@ * @param {string} [config.fileName = undefined] | ||
onError: undefined, | ||
onProgress: undefined | ||
onProgress: undefined, | ||
method: 'GET', | ||
} | ||
@@ -125,7 +127,7 @@ | ||
const that = this; | ||
const { url, directory, fileName, cloneFiles, skipExistingFileName, timeout, headers, httpsAgent, proxy, onResponse, onBeforeSave, onProgress, shouldBufferResponse, useSynchronousMode } = that.config; | ||
const { url, method, directory, fileName, cloneFiles, skipExistingFileName, timeout, headers, httpsAgent, proxy, onResponse, onBeforeSave, onProgress, shouldBufferResponse, useSynchronousMode } = that.config; | ||
//Repeat downloading process until success | ||
const {filePath,downloadStatus} = await that._makeUntilSuccessful(async () => { | ||
const download = new Download({ url, directory, fileName, cloneFiles, skipExistingFileName, timeout, headers, httpsAgent, proxy, onResponse, onBeforeSave, onProgress, shouldBufferResponse, useSynchronousMode }); | ||
const download = new Download({ url, method, directory, fileName, cloneFiles, skipExistingFileName, timeout, headers, httpsAgent, proxy, onResponse, onBeforeSave, onProgress, shouldBufferResponse, useSynchronousMode }); | ||
this._currentDownload = download | ||
@@ -132,0 +134,0 @@ |
@@ -15,5 +15,26 @@ const expect = require('expect') | ||
it('Should download a file using POST method', async () => { | ||
const host = randomHost() | ||
nock(`http://www.${host}.com`) | ||
.post('/post') | ||
.reply(200, (uri, requestBody) => { | ||
return fs.createReadStream(Path.join(__dirname, 'fixtures/Desert.jpg')) | ||
},{ | ||
'Content-Type': 'image/jpeg', | ||
'Content-Length': '23642' | ||
}) | ||
const downloader = new Downloader({ | ||
url: `http://www.${host}.com/post`, | ||
directory: "./downloads", | ||
method: 'POST' | ||
}) | ||
const { downloadStatus, filePath } = await downloader.download(); | ||
expect(downloadStatus).toBe('COMPLETE') | ||
expect(filePath).toBe('./downloads/post.jpeg') | ||
await verifyFile('./downloads/post.jpeg', 23642); | ||
}) | ||
it('Should download a picture from data URI', async () => { | ||
@@ -830,10 +851,1 @@ | ||
function doesFileExist(path) { | ||
return new Promise((resolve, reject) => { | ||
fs.readFile(path, (err, data) => { | ||
if (err) | ||
return resolve(false); | ||
resolve(true); | ||
}); | ||
}) | ||
} |
{ | ||
"name": "nodejs-file-downloader", | ||
"version": "4.11.2", | ||
"version": "4.12.0", | ||
"description": "A file downloader for NodeJs", | ||
@@ -5,0 +5,0 @@ "main": "Downloader.js", |
@@ -46,2 +46,3 @@ nodejs-file-downloader is a simple utility for downloading files. It hides the complexity of dealing with streams, redirects, paths and duplicate file names. Can automatically repeat failed downloads. | ||
directory: "./downloads", //This folder will be created, if it doesn't exist. | ||
method: "GET"// "GET" is the default, no need to specify unless you want to use a different method. | ||
}); | ||
@@ -48,0 +49,0 @@ try { |
202812
2144
337