lib/io_streams/paths/s3.rb in iostreams-1.5.1 vs lib/io_streams/paths/s3.rb in iostreams-1.6.0
- old
+ new
@@ -3,10 +3,13 @@
module IOStreams
module Paths
class S3 < IOStreams::Path
attr_reader :bucket_name, :client, :options
+ # Largest file size supported by the S3 copy object api.
+ S3_COPY_OBJECT_SIZE_LIMIT = 5 * 1024 * 1024 * 1024
+
# Arguments:
#
# url: [String]
# Prefix must be: `s3://`
# followed by bucket name,
@@ -186,11 +189,11 @@
target
end
# Make S3 perform direct copies within S3 itself.
def copy_to(target_path, convert: true)
- return super(target_path) if convert
+ return super(target_path) if convert || (size.to_i >= S3_COPY_OBJECT_SIZE_LIMIT)
target = IOStreams.new(target_path)
return super(target) unless target.is_a?(self.class)
source_name = ::File.join(bucket_name, path)
@@ -201,10 +204,10 @@
# Make S3 perform direct copies within S3 itself.
def copy_from(source_path, convert: true)
return super(source_path) if convert
source = IOStreams.new(source_path)
- return super(source) unless source.is_a?(self.class)
+ return super(source) if !source.is_a?(self.class) || (source.size.to_i >= S3_COPY_OBJECT_SIZE_LIMIT)
source_name = ::File.join(source.bucket_name, source.path)
client.copy_object(options.merge(bucket: bucket_name, key: path, copy_source: source_name))
end