zipline 1.1.0 → 1.1.1

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
2
  SHA1:
3
- metadata.gz: 69a1498073cad22c14b800ca508220aadb0f1237
4
- data.tar.gz: 1046ab42fb8678bcb2ad08ca4cd8b4c00f6bf8c7
3
+ metadata.gz: 96ac7be793e58df09d1d469bdc9caf1ebab6738d
4
+ data.tar.gz: c6b3d727ce0b40efdc152180f2d9f39a6c457154
5
5
  SHA512:
6
- metadata.gz: 296f7ba0ba6fa91e78a060b40edbda917ed4c839658faf639f50888d9089b9d992003a5e01348b0b3377b998a7b162bc4548c826569894f29ae6a4f0a632459b
7
- data.tar.gz: 987a45caed0f8956172dff50e438198ddc8e36fe2f65c5a55bab67c5b24bc6df1aff7320f57bfe4c139d6f491963ca496f0e97fc292a4bdedee39ee677e0bd8b
6
+ metadata.gz: f5f83af934fdc07acaa345d62e78ed995529b32b509ee6d828639ba61cd2c7cadc9d9df65df5e27a97293a2ca55e876215569f00aa4ae3e705250d46b7d697bf
7
+ data.tar.gz: 8f3e3cee734917325717aeb8e6ddbe5d49fa1d17409b8ebdf6a168d6fd2fae7af73d92c8b485b70a13c066087024beeadfe0181fdf3ebb068d388febd2a16150
data/README.md CHANGED
@@ -32,38 +32,71 @@ You'll need to be using puma or some other server that supports streaming output
32
32
 
33
33
  ```Ruby
34
34
  class MyController < ApplicationController
35
- # enable streaming responses
36
- include ActionController::Streaming
37
35
  # enable zipline
38
36
  include Zipline
39
37
 
40
38
  def index
41
39
  users = User.all
42
40
  # you can replace user.avatar with any stream or any object that
43
- # responds to :url.
41
+ # responds to :url, :path or :file.
44
42
  # :modification_time is an optional third argument you can use.
45
- files = users.map{ |user| [user.avatar, "#{user.username}.png", modification_time: 1.day.ago] }
43
+ files = users.map{ |user| [user.avatar, "#{user.username}.png", modification_time: 1.day.ago] }
46
44
  zipline(files, 'avatars.zip')
47
45
  end
48
46
  end
49
47
  ```
50
48
 
49
+ ### ActiveStorage
50
+
51
+ ```Ruby
52
+ users = User.all
53
+ files = users.map{ |user| [user.avatar, user.avatar.filename] }
54
+ zipline(files, 'avatars.zip')
55
+ ```
56
+
57
+ ### Carrierwave
58
+
59
+ ```Ruby
60
+ users = User.all
61
+ files = users.map{ |user| [user.avatar, user.avatar_identifier] }
62
+ zipline(files, 'avatars.zip')
63
+ ```
64
+
65
+ ### Paperclip ([deprecated](https://thoughtbot.com/blog/closing-the-trombone))
66
+
67
+ ```Ruby
68
+ users = User.all
69
+ files = users.map{ |user| [user.avatar, user.avatar_file_name] }
70
+ zipline(files, 'avatars.zip')
71
+ ```
72
+
73
+ ### Url
74
+
75
+ If you know the URL of the remote file you want to include, you can just pass in the
76
+ URL directly in place of the attachment object.
77
+ ```Ruby
78
+ avatars = [
79
+ ['http://www.example.com/user1.png', 'user1.png']
80
+ ['http://www.example.com/user2.png', 'user2.png']
81
+ ['http://www.example.com/user3.png', 'user3.png']
82
+ ]
83
+ zipline(avatars, 'avatars.zip')
84
+ ```
85
+
86
+ ### Directories
87
+
51
88
  For directories, just give the files names like "directory/file".
52
89
 
53
- To stream files from a remote URL, use open-uri with a [lazy enumerator](http://ruby-doc.org/core-2.0.0/Enumerator/Lazy.html):
54
90
 
55
91
  ```Ruby
56
- require 'open-uri'
57
92
  avatars = [
58
- # remote_url zip_path
93
+ # remote_url zip_path zip_tricks_options
59
94
  [ 'http://www.example.com/user1.png', 'avatars/user1.png', modification_time: Time.now.utc ]
60
95
  [ 'http://www.example.com/user2.png', 'avatars/user2.png', modification_time: 1.day.ago ]
61
96
  [ 'http://www.example.com/user3.png', 'avatars/user3.png' ]
62
97
  ]
63
- file_mappings = avatars
64
- .lazy # Lazy allows us to begin sending the download immediately instead of waiting to download everything
65
- .map { |url, path| [open(url), path] }
66
- zipline(file_mappings, 'avatars.zip')
98
+
99
+ zipline(avatars, 'avatars.zip')
67
100
  ```
68
101
 
69
102
  ## Contributing
@@ -1,5 +1,4 @@
1
1
  require "zipline/version"
2
- require 'curb'
3
2
  require 'zip_tricks'
4
3
  require "zipline/zip_generator"
5
4
 
@@ -1,3 +1,3 @@
1
1
  module Zipline
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -47,15 +47,17 @@ module Zipline
47
47
  elsif is_io?(file)
48
48
  {file: file}
49
49
  elsif defined?(ActiveStorage::Blob) && file.is_a?(ActiveStorage::Blob)
50
- {url: file.service_url}
50
+ {blob: file}
51
51
  elsif is_active_storage_attachment?(file) || is_active_storage_one?(file)
52
- {url: file.blob.service_url}
52
+ {blob: file.blob}
53
53
  elsif file.respond_to? :url
54
54
  {url: file.url}
55
55
  elsif file.respond_to? :path
56
56
  {file: File.open(file.path)}
57
57
  elsif file.respond_to? :file
58
58
  {file: File.open(file.file)}
59
+ elsif is_url?(file)
60
+ {url: file}
59
61
  else
60
62
  raise(ArgumentError, 'Bad File/Stream')
61
63
  end
@@ -64,17 +66,18 @@ module Zipline
64
66
  def write_file(streamer, file, name, options)
65
67
  streamer.write_deflated_file(name, options) do |writer_for_file|
66
68
  if file[:url]
67
- the_remote_url = file[:url]
68
- c = Curl::Easy.new(the_remote_url) do |curl|
69
- curl.on_body do |data|
70
- writer_for_file << data
71
- data.bytesize
69
+ the_remote_uri = URI(file[:url])
70
+
71
+ Net::HTTP.get_response(the_remote_uri) do |response|
72
+ response.read_body do |chunk|
73
+ writer_for_file << chunk
72
74
  end
73
75
  end
74
- c.perform
75
76
  elsif file[:file]
76
77
  IO.copy_stream(file[:file], writer_for_file)
77
78
  file[:file].close
79
+ elsif file[:blob]
80
+ file[:blob].download { |chunk| writer_for_file << chunk }
78
81
  else
79
82
  raise(ArgumentError, 'Bad File/Stream')
80
83
  end
@@ -94,5 +97,10 @@ module Zipline
94
97
  def is_active_storage_one?(file)
95
98
  defined?(ActiveStorage::Attached::One) && file.is_a?(ActiveStorage::Attached::One)
96
99
  end
100
+
101
+ def is_url?(url)
102
+ url = URI.parse(url) rescue false
103
+ url.kind_of?(URI::HTTP) || url.kind_of?(URI::HTTPS)
104
+ end
97
105
  end
98
106
  end
@@ -95,38 +95,38 @@ describe Zipline::ZipGenerator do
95
95
  end
96
96
 
97
97
  context "Attached::One" do
98
- it "extracts url" do
98
+ it "get blob" do
99
99
  attached = create_attached_one
100
100
  allow_any_instance_of(Object).to receive(:defined?).and_return(true)
101
101
 
102
102
  normalized = generator.normalize(attached)
103
103
 
104
- expect(normalized.keys).to include(:url)
105
- expect(normalized[:url]).to eq('fakeurl')
104
+ expect(normalized.keys).to include(:blob)
105
+ expect(normalized[:blob]).to be_a(ActiveStorage::Blob)
106
106
  end
107
107
  end
108
108
 
109
109
  context "Attachment" do
110
- it "extracts url" do
110
+ it "get blob" do
111
111
  attachment = create_attachment
112
112
  allow_any_instance_of(Object).to receive(:defined?).and_return(true)
113
113
 
114
114
  normalized = generator.normalize(attachment)
115
115
 
116
- expect(normalized.keys).to include(:url)
117
- expect(normalized[:url]).to eq('fakeurl')
116
+ expect(normalized.keys).to include(:blob)
117
+ expect(normalized[:blob]).to be_a(ActiveStorage::Blob)
118
118
  end
119
119
  end
120
120
 
121
121
  context "Blob" do
122
- it "extracts url" do
122
+ it "get blob" do
123
123
  blob = create_blob
124
124
  allow_any_instance_of(Object).to receive(:defined?).and_return(true)
125
125
 
126
126
  normalized = generator.normalize(blob)
127
127
 
128
- expect(normalized.keys).to include(:url)
129
- expect(normalized[:url]).to eq('fakeurl')
128
+ expect(normalized.keys).to include(:blob)
129
+ expect(normalized[:blob]).to be_a(ActiveStorage::Blob)
130
130
  end
131
131
  end
132
132
 
@@ -14,8 +14,8 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "zipline"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Zipline::VERSION
17
+ gem.licenses = ['MIT']
17
18
 
18
19
  gem.add_dependency 'zip_tricks', ['>= 4.2.1', '<= 5.0.0']
19
20
  gem.add_dependency 'rails', ['>= 3.2.1', '< 6.1']
20
- gem.add_dependency 'curb', ['>= 0.8.0', '< 0.10']
21
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipline
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ram Dobson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-21 00:00:00.000000000 Z
11
+ date: 2019-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zip_tricks
@@ -50,26 +50,6 @@ dependencies:
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '6.1'
53
- - !ruby/object:Gem::Dependency
54
- name: curb
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- version: 0.8.0
60
- - - "<"
61
- - !ruby/object:Gem::Version
62
- version: '0.10'
63
- type: :runtime
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: 0.8.0
70
- - - "<"
71
- - !ruby/object:Gem::Version
72
- version: '0.10'
73
53
  description: a module for streaming dynamically generated zip files
74
54
  email:
75
55
  - ram.dobson@solsystemscompany.com
@@ -90,7 +70,8 @@ files:
90
70
  - spec/spec_helper.rb
91
71
  - zipline.gemspec
92
72
  homepage: http://github.com/fringd/zipline
93
- licenses: []
73
+ licenses:
74
+ - MIT
94
75
  metadata: {}
95
76
  post_install_message:
96
77
  rdoc_options: []