Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

download-to-file

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

download-to-file - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

6

index.js

@@ -10,3 +10,3 @@ 'use strict'

module.exports = function (url, dir, name, cb) {
module.exports = function (url, filepath, cb) {
var transport = url.indexOf('https://') === 0 ? https : http

@@ -20,5 +20,5 @@ return transport.get(url, function (res) {

}
mkdirp(dir, function (err) {
mkdirp(path.dirname(filepath), function (err) {
if (err) return cb(err)
var file = fs.createWriteStream(path.join(dir, name))
var file = fs.createWriteStream(filepath)
pump(res, file, cb)

@@ -25,0 +25,0 @@ })

{
"name": "download-to-file",
"version": "1.0.0",
"version": "2.0.0",
"description": "Download a file to disk programmatically",

@@ -35,5 +35,5 @@ "main": "index.js",

"coordinates": [
53.56204936448514,
9.985748261450226
53.561964585443945,
9.98561523076171
]
}

@@ -20,3 +20,3 @@ # download-to-file

console.log('Downloading to /tmp/example.html')
download('http://example.com/', '/tmp', 'example.html', function (err) {
download('http://example.com/', '/tmp/example.html', function (err) {
if (err) throw err

@@ -29,7 +29,7 @@ console.log('Download finished')

### `download(url, directory, filename, callback)`
### `download(url, filepath, callback)`
Will download the content of the given `url` and store it in `filename`
inside the `directory`. When done, the `callback` will be called with an
optional error object as the first argument.
Will download the content of the given `url` and store it in a file
specified by `filepath`. When done, the `callback` will be called with
an optional error object as the first argument.

@@ -36,0 +36,0 @@ If the server does not return a 200 HTTP status code, the callback will

@@ -19,5 +19,4 @@ 'use strict'

var url = 'http://localhost:' + server.address().port
var filename = Date.now() + '.tmp'
var file = path.join(DIR, filename)
download(url, DIR, filename, function (err) {
var file = path.join(DIR, String(Date.now()))
download(url, file, function (err) {
t.error(err)

@@ -40,5 +39,4 @@ t.ok(fs.existsSync(file))

var url = 'http://localhost:' + server.address().port
var filename = Date.now() + '.tmp'
var file = path.join(DIR, filename)
download(url, DIR, filename, function (err) {
var file = path.join(DIR, String(Date.now()))
download(url, file, function (err) {
t.equal(err.code, 500)

@@ -45,0 +43,0 @@ t.equal(err.message, 'Unexpected HTTP status code: 500')

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc