test.js
754 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var dl = require('./index.js')
var url = "i.imgur.com/G9bDaPH.jpg"
var opts = {
directory: "./images/cats/",
filename: "cat.gif"
}
dl(url, opts, function(err){
if (err) hiss(err)
meow("no protocol")
})
var url = "http://i.imgur.com/G9bDaPH.jpg"
var opts = {
directory: "./images/cats/",
filename: "cat.gif"
}
dl(url, opts, function(err){
if (err) hiss(err)
meow("http protocol")
})
var url = "http://i.imgur.com/G9bDaPH.jpg"
var opts = {
directory: "./images/cats/",
filename: "cat.gif"
}
dl(url, opts, function(err){
if (err) hiss(err)
meow("https protocol")
})
function meow(msg) {
console.log("\033[32m", "meow: " + msg, "\033[91m")
}
function hiss(err) {
console.log("\033[31m", "hiss", "\033[91m")
throw err
}