zipline 1.2.1 → 1.4.0

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
- SHA1:
3
- metadata.gz: 60e9847b29f301c7d2a2b7ff9614454f0e3a1193
4
- data.tar.gz: b9b391b9478f96f0fa067918e4368a5415332123
2
+ SHA256:
3
+ metadata.gz: 2a6443ee4c55b4c4d623364d8042bb47f8bdea691f23fb2d5261784826e69ec6
4
+ data.tar.gz: 0d82621fb810a72c1c4ebb8bb8f0bd7b1cebd3d237a8809068d16f2b3ee8eb63
5
5
  SHA512:
6
- metadata.gz: e25c8bba3c7b7d6c093637c1323d0a4bb6660e94457e4445cc3e6798f7125e8c5c0b99a334de0430ef4ced180e00a4001c29b6ab9c92525dd0a6eca689b0dbe7
7
- data.tar.gz: db9b45bfb987cf97f025c4c2cbeb818a821bd7968524df56ac44d6eaebea4b8420b634815b6a6cde8ff32976e67b20183f8dfa404a0ffa05b91aef824c645a79
6
+ metadata.gz: 3c5d8ba560e1d17db8207c1e99a5fefa31c59254cc3e55cb876c92a9685ebe9f9351b42c8ee815580bd9dc9e8a18c2c4fd0f5959caacda1450e7a830e3e35060
7
+ data.tar.gz: b075c04c1f16663dd3e71d650cdd1866cb588f2c88eb25319f79872845fb31fc99055bed1be5a6bc59a7412e21d99a1cee1bb8da40aa8d12376b8c45903c27d9
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.1"
2
+ VERSION = "1.4.0"
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
 
data/lib/zipline.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "zipline/version"
2
2
  require 'zip_tricks'
3
3
  require "zipline/zip_generator"
4
+ require 'uri'
4
5
 
5
6
  # class MyController < ApplicationController
6
7
  # include Zipline
@@ -13,7 +14,7 @@ require "zipline/zip_generator"
13
14
  module Zipline
14
15
  def zipline(files, zipname = 'zipline.zip')
15
16
  zip_generator = ZipGenerator.new(files)
16
- headers['Content-Disposition'] = "attachment; filename=\"#{zipname.gsub '"', '\"'}\""
17
+ headers['Content-Disposition'] = "attachment; filename=\"#{zipname.gsub '"', '\"'}\"; filename*=UTF-8''#{URI.encode_www_form_component(zipname)}"
17
18
  headers['Content-Type'] = Mime::Type.lookup_by_extension('zip').to_s
18
19
  response.sending_file = true
19
20
  response.cache_control[:public] ||= false
@@ -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 'actionpack', ['>= 3.2.1', '< 8.0']
19
20
  gem.add_dependency 'zip_tricks', ['>= 4.2.1', '< 6.0']
20
- gem.add_dependency 'rails', ['>= 3.2.1', '< 6.1']
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.1
4
+ version: 1.4.0
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-25 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
19
+ version: 3.2.1
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.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
29
+ version: 3.2.1
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.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: