s3_zipper 1.0.7 → 1.0.8
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/Gemfile.lock +5 -3
- data/README.md +20 -1
- data/lib/s3_zipper/version.rb +1 -1
- data/lib/s3_zipper.rb +28 -11
- data/s3_zipper.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69878c0fb5a4fb5db952cb06bd39ecbb5496cc90eb31fa077d79f78287d3dcab
|
4
|
+
data.tar.gz: 269235d7dbba3e2fabab96d7c86def16db1d440f88c6f73a1f12b3e5f94c1bbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51cebd463cf8b28e52ea8b886dbd1ef781e9660ad2bd3d91d75bf3a5b00aafc10348aad6105959167eb9de7265ad2d3a1c6407035b60c0be425aeb6ef8adc055
|
7
|
+
data.tar.gz: ca83241c626075f6e2ec7ed67c27a50b99717ce66d384f9b6937cb0e94e20acc4835c8eb89583b536abe89634a6cf8c596db13afc48e4743a0260af386d39fa9
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
s3_zipper (1.0.
|
4
|
+
s3_zipper (1.0.8)
|
5
5
|
aws-sdk-s3 (~> 1)
|
6
6
|
concurrent-ruby (~> 1.1)
|
7
|
+
multiblock (~> 0.2.1)
|
7
8
|
ruby-progressbar (~> 1)
|
8
9
|
rubyzip (>= 1.0.0)
|
9
10
|
|
@@ -12,8 +13,8 @@ GEM
|
|
12
13
|
specs:
|
13
14
|
ast (2.4.0)
|
14
15
|
aws-eventstream (1.0.3)
|
15
|
-
aws-partitions (1.
|
16
|
-
aws-sdk-core (3.54.
|
16
|
+
aws-partitions (1.170.0)
|
17
|
+
aws-sdk-core (3.54.1)
|
17
18
|
aws-eventstream (~> 1.0, >= 1.0.2)
|
18
19
|
aws-partitions (~> 1.0)
|
19
20
|
aws-sigv4 (~> 1.1)
|
@@ -33,6 +34,7 @@ GEM
|
|
33
34
|
jaro_winkler (1.5.2)
|
34
35
|
jmespath (1.4.0)
|
35
36
|
json (2.2.0)
|
37
|
+
multiblock (0.2.1)
|
36
38
|
parallel (1.17.0)
|
37
39
|
parser (2.6.3.0)
|
38
40
|
ast (~> 2.4.0)
|
data/README.md
CHANGED
@@ -46,6 +46,25 @@ zipper.zip_to_s3(keys)
|
|
46
46
|
# }
|
47
47
|
```
|
48
48
|
|
49
|
+
### Event Handling
|
50
|
+
```ruby
|
51
|
+
keys = ["documents/files/790/306/985/original/background-10.jpg", "documents/files/790/307/076/original/background-10.jpg"]
|
52
|
+
zipper.zip_to_s3 keys do
|
53
|
+
on.start { puts 'Starting to zip' }
|
54
|
+
on.progress { |progress| puts progress.percentage }
|
55
|
+
on.finish { puts 'Finished zipping' }
|
56
|
+
on.upload { puts 'Upload complete' }
|
57
|
+
end
|
58
|
+
# {
|
59
|
+
# :key=>"3dc29e9ba0a069eb5d0783f07b12e1b3.zip",
|
60
|
+
# :url => "https://bucket_name.s3.us-west-2.amazonaws.com/35b6f0e2ee91aa0e3c0640c7a4b2b7db.zip"
|
61
|
+
# :zipped=>["documents/files/790/306/985/original/background-10.jpg", "documents/files/790/307/076/original/background-10.jpg"],
|
62
|
+
# :failed=>[]
|
63
|
+
# }
|
64
|
+
```
|
65
|
+
|
66
|
+
|
67
|
+
|
49
68
|
## Development
|
50
69
|
|
51
70
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -54,7 +73,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
54
73
|
|
55
74
|
## Contributing
|
56
75
|
|
57
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
76
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/capshareinc/s3_zipper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
58
77
|
|
59
78
|
## License
|
60
79
|
|
data/lib/s3_zipper/version.rb
CHANGED
data/lib/s3_zipper.rb
CHANGED
@@ -5,9 +5,10 @@ require "s3_zipper/progress"
|
|
5
5
|
require "s3_zipper/spinner"
|
6
6
|
require "s3_zipper/client"
|
7
7
|
require "zip"
|
8
|
+
require "multiblock"
|
8
9
|
|
9
10
|
class S3Zipper
|
10
|
-
attr_accessor :client, :options, :progress, :zip_client
|
11
|
+
attr_accessor :client, :options, :progress, :zip_client, :wrapper
|
11
12
|
|
12
13
|
# @param [String] bucket - bucket that files exist in
|
13
14
|
# @param [Hash] options - options for zipper
|
@@ -15,6 +16,7 @@ class S3Zipper
|
|
15
16
|
# @return [S3Zipper]
|
16
17
|
def initialize bucket, options = {}
|
17
18
|
@options = options
|
19
|
+
@wrapper = Multiblock.wrapper
|
18
20
|
@progress = Progress.new(enabled: options[:progress], format: "%e %c/%C %t", total: nil, length: 80, autofinish: false)
|
19
21
|
@client = Client.new(bucket, options)
|
20
22
|
@zip_client = Client.new(options[:zip_bucket], options) if options[:zip_bucket]
|
@@ -25,18 +27,20 @@ class S3Zipper
|
|
25
27
|
# @param [Array] keys - Array of s3 keys to zip
|
26
28
|
# @param [String, File] file - Filename or file object for the zip, defaults to a random string
|
27
29
|
# @return [Hash]
|
28
|
-
def zip_to_local_file keys, file: SecureRandom.hex
|
30
|
+
def zip_to_local_file keys, file: SecureRandom.hex
|
31
|
+
yield(wrapper) if block_given?
|
29
32
|
file = file.is_a?(File) ? file : File.open("#{file}.zip", "w")
|
30
|
-
zip(keys, file.path
|
33
|
+
zip(keys, file.path)
|
31
34
|
end
|
32
35
|
|
33
36
|
# Zips files from s3 to a temporary zip
|
34
37
|
# @param [Array] keys - Array of s3 keys to zip
|
35
38
|
# @param [String, File] filename - Name of file, defaults to a random string
|
36
39
|
# @return [Hash]
|
37
|
-
def zip_to_tempfile keys, filename: SecureRandom.hex, cleanup: false
|
40
|
+
def zip_to_tempfile keys, filename: SecureRandom.hex, cleanup: false
|
41
|
+
yield(wrapper) if block_given?
|
38
42
|
zipfile = Tempfile.new([filename, ".zip"])
|
39
|
-
result = zip(keys, zipfile.path
|
43
|
+
result = zip(keys, zipfile.path)
|
40
44
|
zipfile.unlink if cleanup
|
41
45
|
result
|
42
46
|
end
|
@@ -46,17 +50,29 @@ class S3Zipper
|
|
46
50
|
# @param [String, File] filename - Name of file, defaults to a random string
|
47
51
|
# @param [String] path - path for file in s3
|
48
52
|
# @return [Hash]
|
49
|
-
def zip_to_s3 keys, filename: SecureRandom.hex, path: nil, s3_options: {}
|
53
|
+
def zip_to_s3 keys, filename: SecureRandom.hex, path: nil, s3_options: {}
|
54
|
+
yield(wrapper) if block_given?
|
50
55
|
filename = "#{path ? "#{path}/" : ''}#{filename}.zip"
|
51
|
-
result = zip_to_tempfile(keys, filename: filename, cleanup: false
|
56
|
+
result = zip_to_tempfile(keys, filename: filename, cleanup: false)
|
52
57
|
zip_client.upload(result.delete(:filename), filename, options: s3_options)
|
53
58
|
result[:key] = filename
|
54
59
|
result[:url] = client.get_url(result[:key])
|
60
|
+
wrapper.call(:upload, result)
|
55
61
|
result
|
56
62
|
end
|
57
63
|
|
58
64
|
private
|
59
65
|
|
66
|
+
def add_to_zip zipfile, filename, file, n = 0
|
67
|
+
existing_file = zipfile.find_entry(filename)
|
68
|
+
if existing_file
|
69
|
+
filename = "#{File.basename(filename, ".*").split('(').first}(#{n})#{File.extname(filename)}"
|
70
|
+
add_to_zip(zipfile, filename, file, n + 1)
|
71
|
+
else
|
72
|
+
zipfile.add(filename, file.path)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
60
76
|
# @param [Array] keys - Array of s3 keys to zip
|
61
77
|
# @param [String] path - path to zip
|
62
78
|
# @yield [progress]
|
@@ -64,15 +80,16 @@ class S3Zipper
|
|
64
80
|
def zip keys, path
|
65
81
|
progress.reset total: keys.size, title: "Zipping Keys to #{path}"
|
66
82
|
Zip::File.open(path, Zip::File::CREATE) do |zipfile|
|
83
|
+
wrapper.call(:start, zipfile)
|
67
84
|
@failed, @successful = client.download_keys keys do |file, key|
|
68
85
|
progress.increment title: "Zipping #{key} to #{path}"
|
69
|
-
|
86
|
+
wrapper.call(:progress, progress)
|
70
87
|
next if file.nil?
|
71
|
-
|
72
|
-
zipfile.add(File.basename(key), file.path)
|
88
|
+
add_to_zip(zipfile, File.basename(key), file)
|
73
89
|
end
|
90
|
+
progress.finish(title: "Zipped keys to #{path}")
|
91
|
+
wrapper.call(:finish, zipfile)
|
74
92
|
end
|
75
|
-
progress.finish(title: "Zipped keys to #{path}")
|
76
93
|
@successful.each { |_, temp| temp.unlink }
|
77
94
|
{
|
78
95
|
filename: path,
|
data/s3_zipper.gemspec
CHANGED
@@ -45,6 +45,7 @@ Gem::Specification.new do |spec|
|
|
45
45
|
spec.add_development_dependency "thor"
|
46
46
|
spec.add_dependency "aws-sdk-s3", "~> 1"
|
47
47
|
spec.add_dependency "concurrent-ruby", "~> 1.1"
|
48
|
+
spec.add_dependency "multiblock", "~> 0.2.1"
|
48
49
|
spec.add_dependency "ruby-progressbar", "~> 1"
|
49
50
|
spec.add_dependency "rubyzip", ">= 1.0.0"
|
50
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3_zipper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Capshare
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-06-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -137,6 +137,20 @@ dependencies:
|
|
137
137
|
- - "~>"
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '1.1'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: multiblock
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - "~>"
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 0.2.1
|
147
|
+
type: :runtime
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - "~>"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: 0.2.1
|
140
154
|
- !ruby/object:Gem::Dependency
|
141
155
|
name: ruby-progressbar
|
142
156
|
requirement: !ruby/object:Gem::Requirement
|