down 4.2.0 → 4.2.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/CHANGELOG.md +6 -0
- data/README.md +2 -5
- data/down.gemspec +1 -0
- data/lib/down/chunked_io.rb +3 -1
- data/lib/down/http.rb +1 -1
- data/lib/down/net_http.rb +13 -14
- data/lib/down/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 16efde61a43b30f68aa001eb0f06bdc8403d2e7c
|
|
4
|
+
data.tar.gz: 0e56e5adc2bb0bc0387f7198af7b0063ab577aef
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b2f9108523aea427699de88ffc65f8e6d114d75850317f07bce6c3c7019e7f5add1b52ee660e57c109b526d1a8ea42f81c0944564c17ba6f6b18d537f51f4a69
|
|
7
|
+
data.tar.gz: 535dbb6812caba261e692ec713bf25df4aa57ec97027a1b74474aef060b2c9c182267a0d8008210e760d66826e7c978b898efdf4dc0d66355507c39755d84944
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## 4.2.1 (2018-01-29)
|
|
2
|
+
|
|
3
|
+
* Reduce memory allocation in `Down::ChunkedIO` by 10x when buffer string is used (@janko-m)
|
|
4
|
+
|
|
5
|
+
* Reduce memory allocation in `Down::Http.download` by 10x.
|
|
6
|
+
|
|
1
7
|
## 4.2.0 (2017-12-22)
|
|
2
8
|
|
|
3
9
|
* Handle `:max_redirects` in `Down::NetHttp#open` and follow up to 2 redirects by default (@janko-m)
|
data/README.md
CHANGED
|
@@ -247,10 +247,7 @@ some of open-uri's undesired behaviours:
|
|
|
247
247
|
* allows you to limit maximum number of redirects
|
|
248
248
|
|
|
249
249
|
On the other hand `Down::NetHttp.open` is implemented using Net::HTTP directly,
|
|
250
|
-
as open-uri
|
|
251
|
-
|
|
252
|
-
Since open-uri doesn't expose support for partial downloads,
|
|
253
|
-
`Down::NetHttp.open` is implemented using `Net::HTTP` directly.
|
|
250
|
+
as open-uri doesn't support downloading on-demand.
|
|
254
251
|
|
|
255
252
|
#### Redirects
|
|
256
253
|
|
|
@@ -426,7 +423,7 @@ wget.open("http://nature.com/forest.jpg")
|
|
|
426
423
|
You can run tests with
|
|
427
424
|
|
|
428
425
|
```
|
|
429
|
-
$ rake test
|
|
426
|
+
$ bundle exec rake test
|
|
430
427
|
```
|
|
431
428
|
|
|
432
429
|
The test suite pulls and runs [kennethreitz/httpbin] as a Docker container, so
|
data/down.gemspec
CHANGED
|
@@ -17,6 +17,7 @@ Gem::Specification.new do |spec|
|
|
|
17
17
|
|
|
18
18
|
spec.add_development_dependency "minitest", "~> 5.8"
|
|
19
19
|
spec.add_development_dependency "mocha"
|
|
20
|
+
spec.add_development_dependency "rake"
|
|
20
21
|
spec.add_development_dependency "http", "~> 3.0"
|
|
21
22
|
spec.add_development_dependency "posix-spawn" unless RUBY_ENGINE == "jruby"
|
|
22
23
|
spec.add_development_dependency "http_parser.rb"
|
data/lib/down/chunked_io.rb
CHANGED
|
@@ -148,7 +148,7 @@ module Down
|
|
|
148
148
|
def readpartial(length = nil, outbuf = nil)
|
|
149
149
|
fail IOError, "closed stream" if closed?
|
|
150
150
|
|
|
151
|
-
data = outbuf.
|
|
151
|
+
data = outbuf.clear.force_encoding(@encoding) if outbuf
|
|
152
152
|
|
|
153
153
|
if cache && !cache.eof?
|
|
154
154
|
data = cache.read(length, outbuf)
|
|
@@ -182,6 +182,8 @@ module Down
|
|
|
182
182
|
else
|
|
183
183
|
@buffer = nil
|
|
184
184
|
end
|
|
185
|
+
|
|
186
|
+
buffered_data.clear unless buffered_data.equal?(data)
|
|
185
187
|
end
|
|
186
188
|
|
|
187
189
|
@position += data.bytesize
|
data/lib/down/http.rb
CHANGED
data/lib/down/net_http.rb
CHANGED
|
@@ -66,7 +66,8 @@ module Down
|
|
|
66
66
|
|
|
67
67
|
open_uri_file = open_uri(uri, open_uri_options, follows_remaining: max_redirects)
|
|
68
68
|
|
|
69
|
-
tempfile = ensure_tempfile(open_uri_file)
|
|
69
|
+
tempfile = ensure_tempfile(open_uri_file, File.extname(open_uri_file.base_uri.path))
|
|
70
|
+
OpenURI::Meta.init tempfile, open_uri_file # add back open-uri methods
|
|
70
71
|
tempfile.extend Down::NetHttp::DownloadedFile
|
|
71
72
|
|
|
72
73
|
tempfile
|
|
@@ -132,25 +133,23 @@ module Down
|
|
|
132
133
|
request_error!(exception)
|
|
133
134
|
end
|
|
134
135
|
|
|
135
|
-
# Converts the
|
|
136
|
-
#
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
tempfile
|
|
136
|
+
# Converts the given IO into a Tempfile if it isn't one already (open-uri
|
|
137
|
+
# returns a StringIO when there is less than 10KB of content), and gives
|
|
138
|
+
# it the specified file extension.
|
|
139
|
+
def ensure_tempfile(io, extension)
|
|
140
|
+
tempfile = Tempfile.new(["down-net_http", extension], binmode: true)
|
|
140
141
|
|
|
141
|
-
if
|
|
142
|
+
if io.is_a?(Tempfile)
|
|
142
143
|
# Windows requires file descriptors to be closed before files are moved
|
|
143
|
-
|
|
144
|
+
io.close
|
|
144
145
|
tempfile.close
|
|
145
|
-
FileUtils.mv
|
|
146
|
-
else
|
|
147
|
-
IO.copy_stream(
|
|
148
|
-
|
|
146
|
+
FileUtils.mv io.path, tempfile.path
|
|
147
|
+
else
|
|
148
|
+
IO.copy_stream(io, tempfile)
|
|
149
|
+
io.close
|
|
149
150
|
end
|
|
150
151
|
|
|
151
152
|
tempfile.open
|
|
152
|
-
OpenURI::Meta.init tempfile, open_uri_file # adds open-uri methods
|
|
153
|
-
|
|
154
153
|
tempfile
|
|
155
154
|
end
|
|
156
155
|
|
data/lib/down/version.rb
CHANGED
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: 4.2.
|
|
4
|
+
version: 4.2.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:
|
|
11
|
+
date: 2018-01-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|
|
@@ -38,6 +38,20 @@ dependencies:
|
|
|
38
38
|
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
41
55
|
- !ruby/object:Gem::Dependency
|
|
42
56
|
name: http
|
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|