iostreams 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b743c145f120e461d09eed5b9c7476bacbdaa18453200e1ccc57ec9eef2239c
4
- data.tar.gz: 7c54a49f344e454ef64a1e19e47f2c665b46e675eda34c03e1604668a6543de4
3
+ metadata.gz: 1540cfa116ee75ceb9a5cedf8b3c4e89833fc69033e442ec6c5af990d626c427
4
+ data.tar.gz: 03a4bde845869ec7f3d7f54a7a5aed7f72dfaf999ab50f3435faf481927fb069
5
5
  SHA512:
6
- metadata.gz: 27d4a3875009d1902285a9e01b67032e74e1eac6d295de3400096b01c663de8b14cb594e4ffd8f04154d23cf7cfd4a696dbc33b9651fd200808ff087c00c0dc2
7
- data.tar.gz: 92656ad55f37e5ffb3b4588cc93d6d9c988ce31705f888d4e045d86ffcf5047f4185a8de30bc6c262a48ae7f048433edd00f827d155939db7caa858e5e495bf0
6
+ metadata.gz: bb60c37dcaa87cb5a76894c141e675039d369e3eb5e97079f63f60d15e00bce0f84f82ebeff8812829f85bd743118f09850ea5672f557550e5a26e0f0e9582b9
7
+ data.tar.gz: fab7d76db975e8e8b7f0051e83137b9debe4aeea6da865aa5f7d2e218650d4d789c20629fa9881fbdbdc3763fe89947fd660f0b7c494f955e67c4c9dedcbe175
@@ -3,7 +3,7 @@ require "uri"
3
3
  module IOStreams
4
4
  module Paths
5
5
  class S3 < IOStreams::Path
6
- attr_reader :bucket_name, :client
6
+ attr_reader :bucket_name, :client, :options
7
7
 
8
8
  # Arguments:
9
9
  #
@@ -179,17 +179,36 @@ module IOStreams
179
179
  #
180
180
  # Notes:
181
181
  # - Can copy across buckets.
182
+ # - No stream conversions are applied.
182
183
  def move_to(target_path)
184
+ target = copy_to(target_path, convert: false)
185
+ delete
186
+ target
187
+ end
188
+
189
+ # Make S3 perform direct copies within S3 itself.
190
+ def copy_to(target_path, convert: true)
191
+ return super(target_path) if convert
192
+
183
193
  target = IOStreams.new(target_path)
184
194
  return super(target) unless target.is_a?(self.class)
185
195
 
186
196
  source_name = ::File.join(bucket_name, path)
187
- # TODO: Does/should it also copy metadata?
188
- client.copy_object(bucket: target.bucket_name, key: target.path, copy_source: source_name)
189
- delete
197
+ client.copy_object(options.merge(bucket: target.bucket_name, key: target.path, copy_source: source_name))
190
198
  target
191
199
  end
192
200
 
201
+ # Make S3 perform direct copies within S3 itself.
202
+ def copy_from(source_path, convert: true)
203
+ return super(source_path) if convert
204
+
205
+ source = IOStreams.new(source_path)
206
+ return super(source, **args) unless source.is_a?(self.class)
207
+
208
+ source_name = ::File.join(source.bucket_name, source.path)
209
+ client.copy_object(options.merge(bucket: bucket_name, key: path, copy_source: source_name))
210
+ end
211
+
193
212
  # S3 logically creates paths when a key is set.
194
213
  def mkpath
195
214
  self
@@ -220,7 +239,7 @@ module IOStreams
220
239
  # Shortcut method if caller has a filename already with no other streams applied:
221
240
  def read_file(file_name)
222
241
  ::File.open(file_name, "wb") do |file|
223
- client.get_object(@options.merge(response_target: file, bucket: bucket_name, key: path))
242
+ client.get_object(options.merge(response_target: file, bucket: bucket_name, key: path))
224
243
  end
225
244
  end
226
245
 
@@ -248,10 +267,10 @@ module IOStreams
248
267
  # Use multipart file upload
249
268
  s3 = Aws::S3::Resource.new(client: client)
250
269
  obj = s3.bucket(bucket_name).object(path)
251
- obj.upload_file(file_name)
270
+ obj.upload_file(file_name, options)
252
271
  else
253
272
  ::File.open(file_name, "rb") do |file|
254
- client.put_object(@options.merge(bucket: bucket_name, key: path, body: file))
273
+ client.put_object(options.merge(bucket: bucket_name, key: path, body: file))
255
274
  end
256
275
  end
257
276
  end
@@ -177,7 +177,7 @@ module IOStreams
177
177
  end
178
178
 
179
179
  def copy_to(target, convert: true)
180
- target = IOStreams.path(target) unless target.is_a?(Stream)
180
+ target = IOStreams.new(target)
181
181
  target.copy_from(self, convert: convert)
182
182
  end
183
183
 
@@ -1,3 +1,3 @@
1
1
  module IOStreams
2
- VERSION = "1.3.2".freeze
2
+ VERSION = "1.3.3".freeze
3
3
  end
@@ -138,7 +138,7 @@ module Paths
138
138
 
139
139
  it "returns all the children under a sub-dir" do
140
140
  write_raw_data
141
- expected = abd_file_names.collect { |file_name| each_root.join(file_name) }
141
+ expected = %w[abd/test1.txt abd/test5.file].collect { |file_name| each_root.join(file_name) }
142
142
  assert_equal expected.collect(&:to_s).sort, each_root.children("abd/*").collect(&:to_s).sort
143
143
  end
144
144
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iostreams
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-31 00:00:00.000000000 Z
11
+ date: 2020-09-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: