down 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +11 -1
  3. data/down.gemspec +1 -1
  4. data/lib/down.rb +8 -4
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6bfc27c3e2b954afac30e137fa798cf1455914a
4
- data.tar.gz: 3b4dac64774179f307ff94bd235815a404f412f8
3
+ metadata.gz: bba011a45e65446c7b79dbbaf9995b169cd00457
4
+ data.tar.gz: cef8bd02a77da2e1274fdc2fe16247c11b97fe77
5
5
  SHA512:
6
- metadata.gz: 8eea506a22d4f612acbcd6de0cd5b5a1a8416edb8cd768dc2b3f66b3f4f20a26185b978e1a7502278afb6d94c3b9f3ee909028c36ab184a0b425cd1d5b956c96
7
- data.tar.gz: 102506a0f63fd5d87393a9a317bdf2ac60b155fe4467e121000b16c0cd1fe94c444a0383a9ad82a2e40e66fe76ec434d0d6567c5568073dd029a2d01b7a11a84
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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "down"
3
- spec.version = "2.0.0"
3
+ spec.version = "2.0.1"
4
4
  spec.authors = ["Janko Marohnić"]
5
5
  spec.email = ["janko.marohnic@gmail.com"]
6
6
 
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
- raise Down::TooLarge if size && max_size && size > max_size
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
- raise Down::TooLarge if max_size && current_size > max_size
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, "#{error.class}: #{error.message}"
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.path)
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.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-02-03 00:00:00.000000000 Z
11
+ date: 2016-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake