s3_zipper 1.0.1 → 1.0.2
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 +1 -1
- data/README.md +24 -11
- data/lib/s3_zipper/client.rb +13 -7
- data/lib/s3_zipper/version.rb +1 -1
- data/lib/s3_zipper.rb +3 -2
- data/s3_zipper.gemspec +4 -4
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84332cb30a6a397fec7d8177f0e8d3280029390fc59df29cfc3e87751d46e71c
|
4
|
+
data.tar.gz: d77c52979e0fa24a212a764aec88d615b87c6cc0733f1b8880a7a3789ca84b6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 130d0dab10c03d8fb6dadd9169875bd146dd2e881aa8b5cae9846d751044337b890d3b0cb3e180a4cf069b52406844ef946aa8a7d5316bdf28cc7f273a48eb70
|
7
|
+
data.tar.gz: 7f81076f24d724a998dc044422a139590a78ee75ad50a09df2e5b695f02e78b071b495b66df19e0206239cd175c7abe582f807b465954695a38e37a90d2bde98
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# S3Zipper
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
This is a gem for zipping files stored in Amazo n S3
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -21,16 +19,31 @@ Or install it yourself as:
|
|
21
19
|
$ gem install s3_zipper
|
22
20
|
|
23
21
|
## Usage
|
22
|
+
```ruby
|
23
|
+
require 's3_zipper'
|
24
|
+
zipper = S3Zipper.new('bucket_name')
|
25
|
+
```
|
26
|
+
### Zip to local file
|
27
|
+
```ruby
|
28
|
+
keys = ["documents/files/790/306/985/original/background-10.jpg", "documents/files/790/307/076/original/background-10.jpg"]
|
29
|
+
zipper.zip_to_local_file(keys)
|
30
|
+
# {
|
31
|
+
# :filename=>"3dc29e9ba0a069eb5d0783f07b12e1b3.zip",
|
32
|
+
# :zipped=>["documents/files/790/306/985/original/background-10.jpg", "documents/files/790/307/076/original/background-10.jpg"],
|
33
|
+
# :failed=>[]
|
34
|
+
# }
|
35
|
+
```
|
24
36
|
|
37
|
+
### Zip to s3
|
25
38
|
```ruby
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}
|
39
|
+
keys = ["documents/files/790/306/985/original/background-10.jpg", "documents/files/790/307/076/original/background-10.jpg"]
|
40
|
+
zipper.zip_to_s3(keys)
|
41
|
+
# {
|
42
|
+
# :key=>"3dc29e9ba0a069eb5d0783f07b12e1b3.zip",
|
43
|
+
# :url => "https://bucket_name.s3.us-west-2.amazonaws.com/35b6f0e2ee91aa0e3c0640c7a4b2b7db.zip"
|
44
|
+
# :zipped=>["documents/files/790/306/985/original/background-10.jpg", "documents/files/790/307/076/original/background-10.jpg"],
|
45
|
+
# :failed=>[]
|
46
|
+
# }
|
34
47
|
```
|
35
48
|
|
36
49
|
## Development
|
data/lib/s3_zipper/client.rb
CHANGED
@@ -2,7 +2,7 @@ require 'aws-sdk-s3'
|
|
2
2
|
|
3
3
|
class S3Zipper
|
4
4
|
class Client
|
5
|
-
attr_accessor :bucket_name, :
|
5
|
+
attr_accessor :bucket_name, :client, :options, :resource, :pb
|
6
6
|
|
7
7
|
# @param [String] bucket_name - bucket that files exist in
|
8
8
|
# @param [Hash] options - options for zipper
|
@@ -10,13 +10,14 @@ class S3Zipper
|
|
10
10
|
# @return [S3Zipper::Client]
|
11
11
|
def initialize bucket_name, options = {}
|
12
12
|
@bucket_name = bucket_name
|
13
|
-
@
|
13
|
+
@client = options[:client] || ::Aws::S3::Client.new
|
14
|
+
@resource = options[:resource] || ::Aws::S3::Resource.new
|
14
15
|
@options = options
|
15
16
|
@pb = Progress.new(enabled: options[:progress], format: "%e %c/%C %t", total: nil, length: 80, autofinish: false)
|
16
17
|
end
|
17
18
|
|
18
19
|
def download_keys keys
|
19
|
-
pb.reset(total: keys.count, title: 'Downloading Keys')
|
20
|
+
pb.reset(total: keys.count, title: 'Downloading Keys', format: "%e %c/%C %t")
|
20
21
|
keys = keys.map do |key|
|
21
22
|
pb.increment
|
22
23
|
pb.update 'title', "Downloading Key: #{key}"
|
@@ -29,12 +30,12 @@ class S3Zipper
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def download key
|
32
|
-
|
33
|
+
client.get_object bucket: bucket_name, key: key
|
33
34
|
end
|
34
35
|
|
35
36
|
def download_to_file key, target
|
36
37
|
begin
|
37
|
-
|
38
|
+
client.get_object({ bucket: bucket_name, key: key }, target: target)
|
38
39
|
rescue StandardError => e
|
39
40
|
return nil
|
40
41
|
end
|
@@ -52,10 +53,15 @@ class S3Zipper
|
|
52
53
|
temp&.unlink if cleanup
|
53
54
|
end
|
54
55
|
|
56
|
+
def get_url(key)
|
57
|
+
resource.bucket(bucket_name).object(key).public_url
|
58
|
+
end
|
59
|
+
|
55
60
|
def upload local_path, repo_path
|
56
|
-
pb
|
57
|
-
|
61
|
+
pb = Progress.new(enabled: options[:progress], format: '%t', title: "Uploading '#{local_path}' to '#{repo_path}'", length: 120)
|
62
|
+
object = client.put_object(bucket: bucket_name, key: repo_path, body: File.open(local_path).read)
|
58
63
|
pb.finish(title: "Uploaded '#{local_path}' to '#{repo_path}'")
|
64
|
+
object
|
59
65
|
end
|
60
66
|
end
|
61
67
|
end
|
data/lib/s3_zipper/version.rb
CHANGED
data/lib/s3_zipper.rb
CHANGED
@@ -47,8 +47,9 @@ class S3Zipper
|
|
47
47
|
result = zip_to_tempfile(keys, filename: filename, cleanup: false) do |_, progress|
|
48
48
|
yield(progress) if block_given?
|
49
49
|
end
|
50
|
-
client.upload(result
|
51
|
-
result[:
|
50
|
+
client.upload(result.delete(:filename), filename)
|
51
|
+
result[:key] = filename
|
52
|
+
result[:url] = client.get_url(result[:key])
|
52
53
|
result
|
53
54
|
end
|
54
55
|
|
data/s3_zipper.gemspec
CHANGED
@@ -5,12 +5,12 @@ require "s3_zipper/version"
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "s3_zipper"
|
7
7
|
spec.version = S3Zipper::VERSION
|
8
|
-
spec.authors = ["Nickolas Komarnitsky
|
9
|
-
spec.email = ["
|
8
|
+
spec.authors = ["Capshare", 'Nickolas Komarnitsky']
|
9
|
+
spec.email = [""]
|
10
10
|
|
11
11
|
spec.summary = %q{Gem for zipping files in s3}
|
12
12
|
spec.description = %q{}
|
13
|
-
spec.homepage = "https://github.com/
|
13
|
+
spec.homepage = "https://github.com/capshareinc/s3zipper"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
20
20
|
|
21
21
|
spec.metadata["homepage_uri"] = spec.homepage
|
22
|
-
spec.metadata["source_code_uri"] = "https://github.com/
|
22
|
+
spec.metadata["source_code_uri"] = "https://github.com/capshareinc/s3zipper"
|
23
23
|
else
|
24
24
|
raise "RubyGems 2.0 or newer is required to protect against " \
|
25
25
|
"public gem pushes."
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- Capshare
|
7
8
|
- Nickolas Komarnitsky
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date: 2019-
|
12
|
+
date: 2019-05-01 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -138,7 +139,7 @@ dependencies:
|
|
138
139
|
version: '1'
|
139
140
|
description: ''
|
140
141
|
email:
|
141
|
-
-
|
142
|
+
- ''
|
142
143
|
executables:
|
143
144
|
- s3_zipper
|
144
145
|
extensions: []
|
@@ -163,13 +164,13 @@ files:
|
|
163
164
|
- lib/s3_zipper/progress.rb
|
164
165
|
- lib/s3_zipper/version.rb
|
165
166
|
- s3_zipper.gemspec
|
166
|
-
homepage: https://github.com/
|
167
|
+
homepage: https://github.com/capshareinc/s3zipper
|
167
168
|
licenses:
|
168
169
|
- MIT
|
169
170
|
metadata:
|
170
171
|
allowed_push_host: https://rubygems.org
|
171
|
-
homepage_uri: https://github.com/
|
172
|
-
source_code_uri: https://github.com/
|
172
|
+
homepage_uri: https://github.com/capshareinc/s3zipper
|
173
|
+
source_code_uri: https://github.com/capshareinc/s3zipper
|
173
174
|
post_install_message:
|
174
175
|
rdoc_options: []
|
175
176
|
require_paths:
|