Class: S3Zipper
- Inherits:
-
Object
- Object
- S3Zipper
- Defined in:
- lib/s3_zipper.rb,
lib/s3_zipper/client.rb,
lib/s3_zipper/spinner.rb,
lib/s3_zipper/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"3.0.0"
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#options ⇒ Object
Returns the value of attribute options.
-
#progress ⇒ Object
Returns the value of attribute progress.
-
#wrapper ⇒ Object
Returns the value of attribute wrapper.
-
#zip_client ⇒ Object
Returns the value of attribute zip_client.
Instance Method Summary collapse
- #initialize(bucket, options = {}) ⇒ S3Zipper constructor
-
#zip_to_local_file(keys, file: SecureRandom.hex) {|wrapper| ... } ⇒ Hash
Zips files from s3 to a local zip.
-
#zip_to_s3(keys, filename: SecureRandom.hex, path: nil, s3_options: {}) {|wrapper| ... } ⇒ Hash
Zips files from s3 to a temporary file, pushes that to s3, and then cleans up.
-
#zip_to_tempfile(keys, filename: SecureRandom.hex, cleanup: false) {|wrapper| ... } ⇒ Hash
Zips files from s3 to a temporary zip.
Constructor Details
#initialize(bucket, options = {}) ⇒ S3Zipper
17 18 19 20 21 22 23 24 |
# File 'lib/s3_zipper.rb', line 17 def initialize bucket, = {} @options = @wrapper = Multiblock.wrapper @progress = Progress.new(enabled: [:progress], format: "%e %c/%C %t", total: nil, length: 80, autofinish: false) @client = Client.new(bucket, ) @zip_client = Client.new([:zip_bucket], ) if [:zip_bucket] @zip_client ||= @client end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
11 12 13 |
# File 'lib/s3_zipper.rb', line 11 def client @client end |
#options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/s3_zipper.rb', line 11 def @options end |
#progress ⇒ Object
Returns the value of attribute progress.
11 12 13 |
# File 'lib/s3_zipper.rb', line 11 def progress @progress end |
#wrapper ⇒ Object
Returns the value of attribute wrapper.
11 12 13 |
# File 'lib/s3_zipper.rb', line 11 def wrapper @wrapper end |
#zip_client ⇒ Object
Returns the value of attribute zip_client.
11 12 13 |
# File 'lib/s3_zipper.rb', line 11 def zip_client @zip_client end |
Instance Method Details
#zip_to_local_file(keys, file: SecureRandom.hex) {|wrapper| ... } ⇒ Hash
Zips files from s3 to a local zip
30 31 32 33 34 |
# File 'lib/s3_zipper.rb', line 30 def zip_to_local_file keys, file: SecureRandom.hex yield(wrapper) if block_given? file = file.is_a?(File) ? file : File.open("#{file}.zip", "w") zip(keys, file.path) end |
#zip_to_s3(keys, filename: SecureRandom.hex, path: nil, s3_options: {}) {|wrapper| ... } ⇒ Hash
Zips files from s3 to a temporary file, pushes that to s3, and then cleans up
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/s3_zipper.rb', line 53 def zip_to_s3 keys, filename: SecureRandom.hex, path: nil, s3_options: {} yield(wrapper) if block_given? filename = "#{path ? "#{path}/" : ''}#{filename}.zip" result = zip_to_tempfile(keys, filename: filename, cleanup: false) zip_client.upload(result.delete(:filename), filename, options: ) result[:key] = filename result[:url] = zip_client.get_url(result[:key]) wrapper.call(:upload, result) result end |
#zip_to_tempfile(keys, filename: SecureRandom.hex, cleanup: false) {|wrapper| ... } ⇒ Hash
Zips files from s3 to a temporary zip
40 41 42 43 44 45 46 |
# File 'lib/s3_zipper.rb', line 40 def zip_to_tempfile keys, filename: SecureRandom.hex, cleanup: false yield(wrapper) if block_given? zipfile = Tempfile.new([filename, ".zip"]) result = zip(keys, zipfile.path) zipfile.unlink if cleanup result end |