down 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/down.gemspec +1 -1
- data/lib/down.rb +8 -4
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bba011a45e65446c7b79dbbaf9995b169cd00457
|
|
4
|
+
data.tar.gz: cef8bd02a77da2e1274fdc2fe16247c11b97fe77
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f4cd2ee72598b550d1ec39c57472aadcd31b37f825a168f32ccefb2d7c11dbd3b86aeeb4f14d6dd1bb750b27dc0282c18c2c2214f461274bee542c1a6f2a90e6
|
|
7
|
+
data.tar.gz: e3254ce5537d4fc99b870057f8ea647a51af92dfe1d232403d7e72be5b445a012e46306e3a271dbb95228c955804c0d814401d9669cf07f7bbc07c75d7e20f28
|
data/README.md
CHANGED
|
@@ -88,7 +88,17 @@ There are a lot of ways in which a download can fail:
|
|
|
88
88
|
* Request timeout out (`Timeout::Error`)
|
|
89
89
|
|
|
90
90
|
Down unifies all of these errors into one `Down::NotFound` error (because this
|
|
91
|
-
is what actually happened from the outside perspective).
|
|
91
|
+
is what actually happened from the outside perspective). If you want to get the
|
|
92
|
+
actual error raised by open-uri, in Ruby 2.1 or later you can use
|
|
93
|
+
`Exception#cause`:
|
|
94
|
+
|
|
95
|
+
```rb
|
|
96
|
+
begin
|
|
97
|
+
Down.download("http://example.com")
|
|
98
|
+
rescue Down::Error => error
|
|
99
|
+
error.cause #=> #<RuntimeError: HTTP redirection loop: http://example.com>
|
|
100
|
+
end
|
|
101
|
+
```
|
|
92
102
|
|
|
93
103
|
### Timeout
|
|
94
104
|
|
data/down.gemspec
CHANGED
data/lib/down.rb
CHANGED
|
@@ -20,10 +20,14 @@ module Down
|
|
|
20
20
|
downloaded_file = uri.open({
|
|
21
21
|
"User-Agent" => "Down/1.0.0",
|
|
22
22
|
content_length_proc: proc { |size|
|
|
23
|
-
|
|
23
|
+
if size && max_size && size > max_size
|
|
24
|
+
raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)"
|
|
25
|
+
end
|
|
24
26
|
},
|
|
25
27
|
progress_proc: proc { |current_size|
|
|
26
|
-
|
|
28
|
+
if max_size && current_size > max_size
|
|
29
|
+
raise Down::TooLarge, "file is too large (max is #{max_size/1024/1024}MB)"
|
|
30
|
+
end
|
|
27
31
|
progress.call(current_size) if progress
|
|
28
32
|
},
|
|
29
33
|
read_timeout: timeout,
|
|
@@ -44,7 +48,7 @@ module Down
|
|
|
44
48
|
|
|
45
49
|
rescue => error
|
|
46
50
|
raise if error.is_a?(Down::Error)
|
|
47
|
-
raise Down::NotFound, "
|
|
51
|
+
raise Down::NotFound, "file not found"
|
|
48
52
|
end
|
|
49
53
|
|
|
50
54
|
def copy_to_tempfile(basename, io)
|
|
@@ -52,7 +56,7 @@ module Down
|
|
|
52
56
|
if io.is_a?(OpenURI::Meta) && io.is_a?(Tempfile)
|
|
53
57
|
FileUtils.mv io.path, tempfile.path
|
|
54
58
|
else
|
|
55
|
-
IO.copy_stream(io, tempfile
|
|
59
|
+
IO.copy_stream(io, tempfile)
|
|
56
60
|
io.rewind
|
|
57
61
|
end
|
|
58
62
|
tempfile.open
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: down
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Janko Marohnić
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-03-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|