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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 443491ec05f03e75593726f54314b04587637bf2
4
- data.tar.gz: a04c39fd140b7266f7ea80bfee2da4f649c079c4
3
+ metadata.gz: 16efde61a43b30f68aa001eb0f06bdc8403d2e7c
4
+ data.tar.gz: 0e56e5adc2bb0bc0387f7198af7b0063ab577aef
5
5
  SHA512:
6
- metadata.gz: 1a79349a849954e2e68b5bcf187e79825255c9a1c3fd5f1ea81dc12f2d97e4d20a5419443a6e3d3942e82b3af8615fcce24cfcdbd4ded091048d7f02e17d5039
7
- data.tar.gz: 2fb8ed137234217f44790f35a767dead06eecff2174fba0960711ebde04d90ff4ee76f20dced2ab2bd6a48b7e5b31c335556504d6892d9603f6c89092cc7512b
6
+ metadata.gz: b2f9108523aea427699de88ffc65f8e6d114d75850317f07bce6c3c7019e7f5add1b52ee660e57c109b526d1a8ea42f81c0944564c17ba6f6b18d537f51f4a69
7
+ data.tar.gz: 535dbb6812caba261e692ec713bf25df4aa57ec97027a1b74474aef060b2c9c182267a0d8008210e760d66826e7c978b898efdf4dc0d66355507c39755d84944
@@ -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
@@ -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"
@@ -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.replace("").force_encoding(@encoding) if 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
@@ -32,7 +32,7 @@ module Down
32
32
  tempfile = Tempfile.new(["down-http", extname], binmode: true)
33
33
 
34
34
  until io.eof?
35
- tempfile.write(io.readpartial)
35
+ tempfile.write(io.readpartial(nil, buffer ||= String.new))
36
36
 
37
37
  progress_proc.call(tempfile.size) if progress_proc
38
38
 
@@ -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 open-uri result file into a Tempfile if it isn't already,
136
- # and makes sure the Tempfile has the correct file extension.
137
- def ensure_tempfile(open_uri_file)
138
- extension = File.extname(open_uri_file.base_uri.path)
139
- tempfile = Tempfile.new(["down-net_http", extension], binmode: true)
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 open_uri_file.is_a?(Tempfile)
142
+ if io.is_a?(Tempfile)
142
143
  # Windows requires file descriptors to be closed before files are moved
143
- open_uri_file.close
144
+ io.close
144
145
  tempfile.close
145
- FileUtils.mv open_uri_file.path, tempfile.path
146
- else # open-uri returns a StringIO when there is less than 10KB of content
147
- IO.copy_stream(open_uri_file, tempfile)
148
- open_uri_file.close
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen-string-literal: true
2
2
 
3
3
  module Down
4
- VERSION = "4.2.0"
4
+ VERSION = "4.2.1"
5
5
  end
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.0
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: 2017-12-22 00:00:00.000000000 Z
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