zipline 1.2.0 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: '086fee6aad082ec2df7dd4d365631b8294bfe750'
4
- data.tar.gz: b5a29ee5c9f07f3308778e86d1e38bbab4e30c9c
2
+ SHA256:
3
+ metadata.gz: 3b817672135a701f0f20b0fdfdb59404e7328eb20f2d7bc2177fedc02c23905e
4
+ data.tar.gz: 50cb1d70a9a08d9fad93e08283706419bd6c1b372eb65fc9820d5d30cf3eec07
5
5
  SHA512:
6
- metadata.gz: c35318bba3cd50cdf646d554684a20e38370ac3a65cf95a00ff20b1cb126a89b6d817d0211f304bd82ed9c5c19b3581dd93f48e5983c546cf0340e189ae40606
7
- data.tar.gz: 813606c2493ee439340063e98080668a4544b0a5bff5f319a570db43f2bb5dbc37e0595446155af7946d26daeef46928efbaad20dea6f9f1a5d2eb146ee4ad77
6
+ metadata.gz: 18943a6b1515d8747dbb7a748963645655c3fb260b6b45e387938eb4e3c7619a73afd0563fd695060d60986f2e8a7ae09b0195791be3354e5e5ad07a0acc4124
7
+ data.tar.gz: f27c6da446d0d0fe8ce3386a2a6bc53a23c5444c77fa3e2e64dadfada172b277af156719d6031774812573056e69b7bfa4133d11a3f7bcf46e73caa737afda6c
data/.travis.yml CHANGED
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.3
5
4
  - 2.4
6
5
  - 2.5
7
6
  - 2.6
8
7
  - 2.7
8
+ - 3.0
data/Gemfile CHANGED
@@ -5,12 +5,10 @@ gemspec
5
5
 
6
6
  group :development, :test do
7
7
  gem 'rspec', '~> 3'
8
- gem 'fog'
9
8
  gem 'fog-aws'
10
9
  gem 'activesupport'
11
- gem 'aws-sdk'
10
+ gem 'aws-sdk-s3'
12
11
  gem 'carrierwave'
13
12
  gem 'paperclip'
14
13
  gem 'rake'
15
- gem 'rake-rspec'
16
14
  end
data/Rakefile CHANGED
@@ -1,4 +1,12 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
- require "rake/rspec"
4
- task :default => :spec
3
+
4
+ begin
5
+ require 'rspec/core/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task default: :spec
10
+ rescue LoadError
11
+ # no rspec available
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Zipline
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.2"
3
3
  end
@@ -14,11 +14,27 @@ module Zipline
14
14
 
15
15
  def each(&block)
16
16
  fake_io_writer = ZipTricks::BlockWrite.new(&block)
17
- ZipTricks::Streamer.open(fake_io_writer) do |streamer|
17
+ # ZipTricks outputs lots of strings in rapid succession, and with
18
+ # servers it can be beneficial to avoid doing too many tiny writes so that
19
+ # the number of syscalls is minimized. See https://github.com/WeTransfer/zip_tricks/issues/78
20
+ # There is a built-in facility for this in ZipTricks which can be used to implement
21
+ # some cheap buffering here (it exists both in version 4 and version 5). The buffer is really
22
+ # tiny and roughly equal to the medium Linux socket buffer size (16 KB). Although output
23
+ # will be not so immediate with this buffering the overall performance will be better,
24
+ # especially with multiple clients being serviced at the same time.
25
+ # Note that the WriteBuffer writes the same, retained String object - but the contents
26
+ # of that object changes between calls. This should work fine with servers where the
27
+ # contents of the string gets written to a socket immediately before the execution inside
28
+ # the WriteBuffer resumes), but if the strings get retained somewhere - like in an Array -
29
+ # this might pose a problem. Unlikely that it will be an issue here though.
30
+ write_buffer_size = 16 * 1024
31
+ write_buffer = ZipTricks::WriteBuffer.new(fake_io_writer, write_buffer_size)
32
+ ZipTricks::Streamer.open(write_buffer) do |streamer|
18
33
  @files.each do |file, name, options = {}|
19
- handle_file(streamer, file, name, options)
34
+ handle_file(streamer, file, name.to_s, options)
20
35
  end
21
36
  end
37
+ write_buffer.flush! # for any remaining writes
22
38
  end
23
39
 
24
40
  def handle_file(streamer, file, name, options)
@@ -64,7 +80,7 @@ module Zipline
64
80
  end
65
81
 
66
82
  def write_file(streamer, file, name, options)
67
- streamer.write_deflated_file(name, options) do |writer_for_file|
83
+ streamer.write_deflated_file(name, **options.slice(:modification_time)) do |writer_for_file|
68
84
  if file[:url]
69
85
  the_remote_uri = URI(file[:url])
70
86
 
@@ -1,6 +1,23 @@
1
1
  require 'spec_helper'
2
2
  require 'tempfile'
3
3
 
4
+ module ActiveStorage
5
+ class Attached
6
+ class One < Attached
7
+ end
8
+ end
9
+ class Attachment; end
10
+ class Blob; end
11
+ class Filename
12
+ def initialize(name)
13
+ @name = name
14
+ end
15
+ def to_s
16
+ @name
17
+ end
18
+ end
19
+ end
20
+
4
21
  describe Zipline::ZipGenerator do
5
22
  before { Fog.mock! }
6
23
  let(:file_attributes){ {
@@ -85,15 +102,6 @@ describe Zipline::ZipGenerator do
85
102
  end
86
103
  end
87
104
  context "ActiveStorage" do
88
- module ActiveStorage
89
- class Attached
90
- class One < Attached
91
- end
92
- end
93
- class Attachment; end
94
- class Blob; end
95
- end
96
-
97
105
  context "Attached::One" do
98
106
  it "get blob" do
99
107
  attached = create_attached_one
@@ -147,8 +155,15 @@ describe Zipline::ZipGenerator do
147
155
  def create_blob
148
156
  blob = ActiveStorage::Blob.new
149
157
  allow(blob).to receive(:service_url).and_return('fakeurl')
158
+ filename = create_filename
159
+ allow(blob).to receive(:filename).and_return(filename)
150
160
  blob
151
161
  end
162
+
163
+ def create_filename
164
+ # Rails wraps Blob#filname in this class since Rails 5.2
165
+ ActiveStorage::Filename.new('test')
166
+ end
152
167
  end
153
168
  context "Fog" do
154
169
  it "extracts url" do
@@ -171,6 +186,25 @@ describe Zipline::ZipGenerator do
171
186
  end
172
187
  end
173
188
 
189
+ describe '.write_file' do
190
+ let(:file) { StringIO.new('passthrough') }
191
+
192
+ context 'when passing an ActiveStorage::Filename object as filename' do
193
+ let(:filename) { ActiveStorage::Filename.new('test') }
194
+
195
+ let(:generator) do
196
+ Zipline::ZipGenerator.new([[file, filename]])
197
+ end
198
+
199
+ it 'passes a string as filename to ZipTricks' do
200
+ allow(file).to receive(:url).and_return('fakeurl')
201
+ expect_any_instance_of(ZipTricks::Streamer).to receive(:write_deflated_file)
202
+ .with('test')
203
+ generator.each { |_| 'Test' }
204
+ end
205
+ end
206
+ end
207
+
174
208
  describe 'passing an options hash' do
175
209
  let(:file) { StringIO.new('passthrough') }
176
210
 
@@ -186,7 +220,7 @@ describe Zipline::ZipGenerator do
186
220
  generator.each { |_| 'Test' }
187
221
  end
188
222
 
189
- it 'passes the options hash to ZipTricks' do
223
+ it 'passes the options hash to ZipTricks as kwargs' do
190
224
  allow(file).to receive(:url).and_return('fakeurl')
191
225
  expect_any_instance_of(ZipTricks::Streamer).to receive(:write_deflated_file)
192
226
  .with(anything, modification_time: mtime)
@@ -205,10 +239,30 @@ describe Zipline::ZipGenerator do
205
239
  generator.each { |_| 'Test' }
206
240
  end
207
241
 
208
- it 'passes the options hash to ZipTricks' do
242
+ it 'passes the options hash to ZipTricks as kwargs' do
243
+ allow(file).to receive(:url).and_return('fakeurl')
244
+ expect_any_instance_of(ZipTricks::Streamer).to receive(:write_deflated_file)
245
+ .with(anything)
246
+ generator.each { |_| 'Test' }
247
+ end
248
+ end
249
+
250
+ context 'with extra invalid options' do
251
+ let(:mtime) { 1.day.ago }
252
+ let(:generator) do
253
+ Zipline::ZipGenerator.new([[file, 'test', modification_time: mtime, extra: 'invalid']])
254
+ end
255
+
256
+ it 'passes the whole options hash through handle_file' do
257
+ expect(generator).to receive(:handle_file)
258
+ .with(anything, anything, anything, { modification_time: mtime, extra: 'invalid' })
259
+ generator.each { |_| 'Test' }
260
+ end
261
+
262
+ it 'only passes the kwargs to ZipTricks that it expects (i.e., :modification_time)' do
209
263
  allow(file).to receive(:url).and_return('fakeurl')
210
264
  expect_any_instance_of(ZipTricks::Streamer).to receive(:write_deflated_file)
211
- .with(anything, {})
265
+ .with(anything, modification_time: mtime)
212
266
  generator.each { |_| 'Test' }
213
267
  end
214
268
  end
data/spec/spec_helper.rb CHANGED
@@ -2,9 +2,7 @@ require 'rspec'
2
2
  require 'active_support'
3
3
  require 'active_support/core_ext'
4
4
  require 'zipline'
5
- require 'aws-sdk'
6
5
  require 'paperclip'
7
- require 'fog'
8
6
  require 'fog-aws'
9
7
  require 'carrierwave'
10
8
 
@@ -21,8 +19,6 @@ CarrierWave.configure do |config|
21
19
 
22
20
  end
23
21
 
24
-
25
-
26
22
  RSpec.configure do |config|
27
23
  config.color = true
28
24
  config.order = :random
data/zipline.gemspec CHANGED
@@ -16,6 +16,6 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Zipline::VERSION
17
17
  gem.licenses = ['MIT']
18
18
 
19
- gem.add_dependency 'zip_tricks', ['>= 4.2.1', '<= 5.1.0']
20
- gem.add_dependency 'rails', ['>= 3.2.1', '< 6.1']
19
+ gem.add_dependency 'actionpack', ['>= 3.2.1', '< 8.0']
20
+ gem.add_dependency 'zip_tricks', ['>= 4.2.1', '< 6.0']
21
21
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipline
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ram Dobson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-19 00:00:00.000000000 Z
11
+ date: 2022-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: zip_tricks
14
+ name: actionpack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.1
20
- - - "<="
19
+ version: 3.2.1
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 5.1.0
22
+ version: '8.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 4.2.1
30
- - - "<="
29
+ version: 3.2.1
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 5.1.0
32
+ version: '8.0'
33
33
  - !ruby/object:Gem::Dependency
34
- name: rails
34
+ name: zip_tricks
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 3.2.1
39
+ version: 4.2.1
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '6.1'
42
+ version: '6.0'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 3.2.1
49
+ version: 4.2.1
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '6.1'
52
+ version: '6.0'
53
53
  description: a module for streaming dynamically generated zip files
54
54
  email:
55
55
  - ram.dobson@solsystemscompany.com
@@ -73,7 +73,7 @@ homepage: http://github.com/fringd/zipline
73
73
  licenses:
74
74
  - MIT
75
75
  metadata: {}
76
- post_install_message:
76
+ post_install_message:
77
77
  rdoc_options: []
78
78
  require_paths:
79
79
  - lib
@@ -88,9 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
- rubyforge_project:
92
- rubygems_version: 2.6.14
93
- signing_key:
91
+ rubygems_version: 3.2.3
92
+ signing_key:
94
93
  specification_version: 4
95
94
  summary: stream zip files from rails
96
95
  test_files: