s3_zipper 1.0.0 → 1.0.1

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
2
  SHA256:
3
- metadata.gz: ca5799b444022886fe0fde36a96089889a94e1bb14786863af324b6c1cdd9706
4
- data.tar.gz: 6663551cd431d8b2a81aed43afc22d309c21171eecdb9b10c209b6c19bb0d854
3
+ metadata.gz: 4f947d741e4eb65d207ac77dd473b115df2cbcd258b65a47c1b190089ee41041
4
+ data.tar.gz: c23a65147b049ce5b532c78b586404af88c63e78c179fa355cbdc8250237ddb3
5
5
  SHA512:
6
- metadata.gz: 3fb1c262daaa22a426d28471d5bc5e71c38a72671b5c811246a729e0ff8294c09da4b645e48c7060aa7f0a577617321bb6f069ab87d785676c46ff86c033f423
7
- data.tar.gz: be5c2da1e3223029089be6139389a142d36d71d2f755d303411351ccaaec696ddacb0673e17f7a0ef363add24913aa012692b2376d788e12e15a9ed7da64272b
6
+ metadata.gz: ecb2ebc22d9773907271bab4fb58c07c62858b1c7b1fe60be832b5fae46bdf10a2873c240d3e1c50fd2c1eeb3e59ef02325a73ad2ae4f364b89020db984619b3
7
+ data.tar.gz: 831da1cc6238f1a49851554cb605f80c857388a5e83d3e1256d822b9c5704898925bd66007bc598ed728528b27bf72dc4d323183f88bc026a626c93783a74a58
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- s3_zipper (0.1.0)
4
+ s3_zipper (1.0.1)
5
5
  aws-sdk-s3 (~> 1)
6
6
  ruby-progressbar (~> 1)
7
7
  rubyzip (>= 1.0.0)
@@ -10,8 +10,8 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  aws-eventstream (1.0.3)
13
- aws-partitions (1.155.0)
14
- aws-sdk-core (3.48.6)
13
+ aws-partitions (1.156.0)
14
+ aws-sdk-core (3.49.0)
15
15
  aws-eventstream (~> 1.0, >= 1.0.2)
16
16
  aws-partitions (~> 1.0)
17
17
  aws-sigv4 (~> 1.1)
data/README.md CHANGED
@@ -25,7 +25,7 @@ Or install it yourself as:
25
25
  ```ruby
26
26
  zipper = S3Zipper.new(ENV['AWS_BUCKET'])
27
27
  files = ["documents/files/790/306/985/original/background-10.jpg", "documents/files/790/307/076/original/background-10.jpg", "documents/files/790/307/029/original/background-10.jpg", "documents/files/790/307/031/original/background-11.jpg", "documents/files/790/307/077/original/background-11.jpg", "documents/files/790/306/983/original/background-11.jpg", "documents/files/790/306/986/original/background-12.jpg", "documents/files/790/307/078/original/background-12.jpg", "documents/files/790/307/032/original/background-12.jpg", "documents/files/790/306/987/original/background-13.jpg"]
28
- zipper.zip_files(files)
28
+ zipper.zip_to_local_file(files)
29
29
  {
30
30
  :filename=>"3dc29e9ba0a069eb5d0783f07b12e1b3.zip",
31
31
  :zipped=>["documents/files/790/306/985/original/background-10.jpg", "documents/files/790/307/076/original/background-10.jpg", "documents/files/790/307/029/original/background-10.jpg", "documents/files/790/307/031/original/background-11.jpg", "documents/files/790/307/077/original/background-11.jpg", "documents/files/790/306/983/original/background-11.jpg", "documents/files/790/306/986/original/background-12.jpg", "documents/files/790/307/078/original/background-12.jpg", "documents/files/790/307/032/original/background-12.jpg", "documents/files/790/306/987/original/background-13.jpg"],
@@ -4,6 +4,10 @@ class S3Zipper
4
4
  class Client
5
5
  attr_accessor :bucket_name, :s3, :options, :pb
6
6
 
7
+ # @param [String] bucket_name - bucket that files exist in
8
+ # @param [Hash] options - options for zipper
9
+ # @option options [Boolean] :progress - toggles progress tracking
10
+ # @return [S3Zipper::Client]
7
11
  def initialize bucket_name, options = {}
8
12
  @bucket_name = bucket_name
9
13
  @s3 = options[:client] || ::Aws::S3::Client.new
@@ -1,3 +1,3 @@
1
1
  class S3Zipper
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/s3_zipper.rb CHANGED
@@ -15,6 +15,10 @@ class S3Zipper
15
15
  @client = Client.new(bucket, options)
16
16
  end
17
17
 
18
+ # Zips files from s3 to a local zip
19
+ # @param [Array] keys - Array of s3 keys to zip
20
+ # @param [String, File] file - Filename or file object for the zip, defaults to a random string
21
+ # @return [Hash]
18
22
  def zip_to_local_file(keys, file: SecureRandom.hex)
19
23
  file = file.is_a?(File) ? file : File.open("#{file}.zip", 'w')
20
24
  zip keys, file.path do |progress|
@@ -22,23 +26,38 @@ class S3Zipper
22
26
  end
23
27
  end
24
28
 
25
- def zip_to_tempfile(keys, filename: SecureRandom.hex)
29
+ # Zips files from s3 to a temporary zip
30
+ # @param [Array] keys - Array of s3 keys to zip
31
+ # @param [String, File] filename - Name of file, defaults to a random string
32
+ # @return [Hash]
33
+ def zip_to_tempfile(keys, filename: SecureRandom.hex, cleanup: false)
26
34
  zipfile = Tempfile.new([filename, '.zip'])
27
- result = zip(keys, zipfile.path)
28
- yield(zipfile, result) if block_given?
29
- zipfile.unlink
35
+ result = zip(keys, zipfile.path) { |progress| yield(zipfile, progress) if block_given? }
36
+ zipfile.unlink if cleanup
30
37
  result
31
38
  end
32
39
 
40
+ # Zips files from s3 to a temporary file, pushes that to s3, and then cleans up
41
+ # @param [Array] keys - Array of s3 keys to zip
42
+ # @param [String, File] filename - Name of file, defaults to a random string
43
+ # @param [String] path - path for file in s3
44
+ # @return [Hash]
33
45
  def zip_to_s3 keys, filename: SecureRandom.hex, path: nil
34
- zip_to_tempfile(keys, filename: filename) do |zipfile, result|
35
- result[:filename] = "#{path ? "#{path}/" : ''}#{filename}.zip"
36
- client.upload(zipfile.path, result[:filename])
46
+ filename = "#{path ? "#{path}/" : ''}#{filename}.zip"
47
+ result = zip_to_tempfile(keys, filename: filename, cleanup: false) do |_, progress|
48
+ yield(progress) if block_given?
37
49
  end
50
+ client.upload(result[:filename], filename)
51
+ result[:filename] = filename
52
+ result
38
53
  end
39
54
 
40
55
  private
41
56
 
57
+ # @param [Array] keys - Array of s3 keys to zip
58
+ # @param [String] path - path to zip
59
+ # @yield [progress]
60
+ # @return [Hash]
42
61
  def zip(keys, path)
43
62
  failed, successful = client.download_keys keys
44
63
  Zip::File.open(path, Zip::File::CREATE) do |zipfile|
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.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nickolas Komarnitsky