iostreams 1.0.0.beta5 → 1.0.0.beta6

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: 2115cf67139790d04fa7efa3df009d0a53a0f00e22d787e35a0f9410e92b4dda
4
- data.tar.gz: b4af1f56d58b164dcee1dc36735ac9e9ec55413ead31feee37edb4c4abcca60f
3
+ metadata.gz: 167014d27ff57416cce79209be3025489a6312e208f3edccebb17f535dae9ae1
4
+ data.tar.gz: 55e1f44b9613010dc81f02bb03d92ee9ec32c2b9d49c4ec99657a9c072700fb7
5
5
  SHA512:
6
- metadata.gz: 0f17f11c7a0e8704827340eeaac6b48823bb72a34eb6da0b9c15d3248596d9638e0fbe6dcdf424fb6e806582ccf9d05f20159b61ef9672a27f04c138775e3f2f
7
- data.tar.gz: f5ca498422999b53d1789276b12ed24afef1b63a0f55bb0454d00b015898df7e936f58f91c68b012b6f2825e2ad2b44a311a2f4e82652d66c07cd4f5f729110e
6
+ metadata.gz: 7d82649bff9f6ff9c97e58caa499c0cf5ce5090553816a76155374d6123b91fb673426c4eddfed0e5da24fff89e77997e7064b87ec95bf7aac0f1bac7b6f9dd0
7
+ data.tar.gz: 97d1fa3c4e5771d4f7ad3e9d3b3580f5b4cadbc5d57838277e7e7fe21224d496b5978e788f54981143d579a39131b907c9b069881e8d2b200356d49b4b2362f8
@@ -38,6 +38,11 @@ module IOStreams
38
38
  super(uri.path)
39
39
  end
40
40
 
41
+ # Does not support relative file names since there is no concept of current working directory
42
+ def relative?
43
+ false
44
+ end
45
+
41
46
  def to_s
42
47
  url
43
48
  end
@@ -15,6 +15,12 @@ module IOStreams
15
15
  # s3://my-bucket-name/file_name.txt
16
16
  # s3://my-bucket-name/some_path/file_name.csv
17
17
  #
18
+ # access_key_id: [String]
19
+ # AWS Access Key Id to use to access this bucket.
20
+ #
21
+ # secret_access_key: [String]
22
+ # AWS Secret Access Key Id to use to access this bucket.
23
+ #
18
24
  # Writer specific options:
19
25
  #
20
26
  # @option params [String] :acl
@@ -124,7 +130,7 @@ module IOStreams
124
130
  #
125
131
  # @option params [String] :object_lock_legal_hold_status
126
132
  # The Legal Hold status that you want to apply to the specified object.
127
- def initialize(url, client: nil, **args)
133
+ def initialize(url, client: nil, access_key_id: nil, secret_access_key: nil, **args)
128
134
  Utils.load_soft_dependency('aws-sdk-s3', 'AWS S3') unless defined?(::Aws::S3::Client)
129
135
 
130
136
  uri = URI.parse(url)
@@ -132,8 +138,14 @@ module IOStreams
132
138
 
133
139
  @bucket_name = uri.host
134
140
  key = uri.path.sub(%r{\A/}, '')
135
- @client = client || ::Aws::S3::Client.new
136
- @options = args
141
+ if client.is_a?(Hash)
142
+ client[:access_key_id] = access_key_id if access_key_id
143
+ client[:secret_access_key] = secret_access_key if secret_access_key
144
+ @client = ::Aws::S3::Client.new(client)
145
+ else
146
+ @client = client || ::Aws::S3::Client.new(access_key_id: access_key_id, secret_access_key: secret_access_key)
147
+ end
148
+ @options = args
137
149
 
138
150
  URI.decode_www_form(uri.query).each { |key, value| @options[key] = value } if uri.query
139
151
 
@@ -144,6 +156,11 @@ module IOStreams
144
156
  ::File.join("s3://", bucket_name, path)
145
157
  end
146
158
 
159
+ # Does not support relative file names since there is no concept of current working directory
160
+ def relative?
161
+ false
162
+ end
163
+
147
164
  def delete
148
165
  client.delete_object(bucket: bucket_name, key: path)
149
166
  self
@@ -73,6 +73,11 @@ module IOStreams
73
73
  super(uri.path)
74
74
  end
75
75
 
76
+ # Does not support relative file names since there is no concept of current working directory
77
+ def relative?
78
+ false
79
+ end
80
+
76
81
  def to_s
77
82
  url
78
83
  end
@@ -204,10 +209,10 @@ module IOStreams
204
209
  options = ssh_options.dup
205
210
  key = options.delete('IdentityKey')
206
211
  # sftp requires that private key is only readable by the current user
207
- File.open(file_name, 'wb', 0600) { |io| io.write(key) }
212
+ ::File.open(file_name, 'wb', 0600) { |io| io.write(key) }
208
213
 
209
214
  options['IdentityFile'] = file_name
210
- yield sftp_args(ssh_options)
215
+ yield sftp_args(options)
211
216
  end
212
217
  end
213
218
 
@@ -1,3 +1,3 @@
1
1
  module IOStreams
2
- VERSION = "1.0.0.beta5".freeze
2
+ VERSION = "1.0.0.beta6".freeze
3
3
  end
@@ -36,28 +36,24 @@ module IOStreams
36
36
  # Read from a zip file or stream, decompressing the contents as it is read
37
37
  # The input stream from the first file found in the zip file is passed
38
38
  # to the supplied block
39
- def self.file(file_name, entry_file_name: nil)
40
- Utils.load_soft_dependency('rubyzip', 'Zip', 'zip') unless defined?(::Zip)
39
+ def self.file(file_name, entry_file_name: nil, &block)
40
+ Utils.load_soft_dependency('rubyzip', 'Read Zip', 'zip') unless defined?(::Zip)
41
41
 
42
- ::Zip::InputStream.open(file_name) do |zin|
43
- get_entry(zin, entry_file_name) ||
44
- raise(::Zip::EntryNameError, "File #{entry_file_name} not found within zip file.")
45
- yield(zin)
42
+ ::Zip::File.open(file_name) do |zip_file|
43
+ if entry_file_name
44
+ zip_file.get_input_stream(entry_file_name, &block)
45
+ else
46
+ result = nil
47
+ # Return the first file
48
+ zip_file.each do |entry|
49
+ result = entry.get_input_stream(&block)
50
+ break
51
+ end
52
+ result
53
+ end
46
54
  end
47
55
  end
48
56
  end
49
-
50
- def self.get_entry(zin, entry_file_name)
51
- if entry_file_name.nil?
52
- zin.get_next_entry
53
- return true
54
- end
55
-
56
- while entry = zin.get_next_entry
57
- return true if entry.name == entry_file_name
58
- end
59
- false
60
- end
61
57
  end
62
58
  end
63
59
  end
@@ -1,59 +1,29 @@
1
1
  module IOStreams
2
2
  module Zip
3
3
  class Writer < IOStreams::Writer
4
- # Write a single file in Zip format to the supplied output file name
4
+ # Write a single file in Zip format to the supplied output stream
5
5
  #
6
6
  # Parameters
7
- # file_name [String]
8
- # Full path and filename for the output zip file.
7
+ # output_stream [IO]
8
+ # Output stream to write to
9
+ #
10
+ # original_file_name [String]
11
+ # Since this is a stream the original file name is used to create the entry_file_name if not supplied
9
12
  #
10
13
  # entry_file_name: [String]
11
14
  # Name of the file entry within the Zip file.
12
15
  #
13
16
  # The stream supplied to the block only responds to #write
14
- #
15
- # Example:
16
- # IOStreams::ZipWriter.open('myfile.zip', zip_file_name: 'myfile.txt') do |io_stream|
17
- # io_stream.write("hello world\n")
18
- # io_stream.write("and more\n")
19
- # end
20
- #
21
- # Notes:
22
- # - Since Zip cannot write to streams, if a stream is supplied, a temp file
23
- # is automatically created under the covers
24
- def self.file(file_name, original_file_name: file_name, zip_file_name: nil, entry_file_name: zip_file_name, &block)
17
+ def self.stream(output_stream, original_file_name: nil, zip_file_name: nil, entry_file_name: zip_file_name, &block)
25
18
  # Default the name of the file within the zip to the supplied file_name without the zip extension
26
- if entry_file_name.nil? && (original_file_name =~ /\.(zip)\z/i)
19
+ if entry_file_name.nil? && original_file_name && (original_file_name =~ /\.(zip)\z/i)
27
20
  entry_file_name = original_file_name.to_s[0..-5]
28
21
  end
29
22
  entry_file_name ||= 'file'
30
23
 
31
- write_file(file_name, entry_file_name, &block)
32
- end
33
-
34
- private
35
-
36
- if defined?(JRuby)
37
- def self.write_file(file_name, entry_file_name)
38
- out = Java::JavaIo::FileOutputStream.new(file_name)
39
- zout = Java::JavaUtilZip::ZipOutputStream.new(out)
40
- zout.put_next_entry(Java::JavaUtilZip::ZipEntry.new(entry_file_name))
41
- io = zout.to_io
42
- yield(io)
43
- ensure
44
- io&.close
45
- out&.close
46
- end
47
- else
48
- def self.write_file(file_name, entry_file_name)
49
- Utils.load_soft_dependency('rubyzip', 'Zip', 'zip') unless defined?(::Zip)
24
+ Utils.load_soft_dependency('zip_tricks', 'Zip') unless defined?(ZipTricks::Streamer)
50
25
 
51
- zos = ::Zip::OutputStream.new(file_name)
52
- zos.put_next_entry(entry_file_name)
53
- yield(zos)
54
- ensure
55
- zos&.close
56
- end
26
+ ZipTricks::Streamer.open(output_stream) { |zip| zip.write_deflated_file(entry_file_name, &block) }
57
27
  end
58
28
  end
59
29
  end
@@ -13,6 +13,7 @@ module Paths
13
13
  let(:username) { ENV["SFTP_USERNAME"] }
14
14
  let(:password) { ENV["SFTP_PASSWORD"] }
15
15
  let(:ftp_dir) { ENV["SFTP_DIR"] || "iostreams_test" }
16
+ let(:identity_username) { ENV["SFTP_IDENTITY_USERNAME"] || username }
16
17
 
17
18
  let(:url) { File.join("sftp://", host_name, ftp_dir) }
18
19
 
@@ -71,7 +72,7 @@ module Paths
71
72
 
72
73
  describe 'use identity file instead of password' do
73
74
  let :root_path do
74
- IOStreams::Paths::SFTP.new(url, username: username, ssh_options: {'IdentityFile' => ENV["SFTP_IDENTITY_FILE"]} )
75
+ IOStreams::Paths::SFTP.new(url, username: identity_username, ssh_options: {'IdentityFile' => ENV["SFTP_IDENTITY_FILE"]})
75
76
  end
76
77
 
77
78
  it 'writes' do
@@ -84,7 +85,7 @@ module Paths
84
85
  describe 'use identity key instead of password' do
85
86
  let :root_path do
86
87
  key = File.open(ENV["SFTP_IDENTITY_FILE"], 'rb', &:read)
87
- IOStreams::Paths::SFTP.new(url, username: username, ssh_options: {'IdentityKey' => key})
88
+ IOStreams::Paths::SFTP.new(url, username: identity_username, ssh_options: {'IdentityKey' => key})
88
89
  end
89
90
 
90
91
  it 'writes' do
@@ -81,16 +81,16 @@ class StreamsTest < Minitest::Test
81
81
 
82
82
  it 'returns the reader' do
83
83
  string_io = StringIO.new
84
- streams.stream(:zip)
84
+ streams.stream(:bz2)
85
85
  streams.reader(string_io) do |io|
86
- assert io.is_a?(::Zip::InputStream), io
86
+ assert io.is_a?(RBzip2::FFI::Decompressor), io
87
87
  end
88
88
  end
89
89
 
90
90
  it 'returns the last reader' do
91
91
  string_io = StringIO.new
92
92
  streams.stream(:encode)
93
- streams.stream(:zip)
93
+ streams.stream(:bz2)
94
94
  streams.reader(string_io) do |io|
95
95
  assert io.is_a?(IOStreams::Encode::Reader), io
96
96
  end
@@ -113,7 +113,7 @@ class StreamsTest < Minitest::Test
113
113
  string_io = StringIO.new
114
114
  streams.stream(:zip)
115
115
  streams.writer(string_io) do |io|
116
- assert io.is_a?(::Zip::OutputStream), io
116
+ assert io.is_a?(ZipTricks::Streamer::Writable), io
117
117
  end
118
118
  end
119
119
 
@@ -24,9 +24,7 @@ class ZipWriterTest < Minitest::Test
24
24
  IOStreams::Zip::Writer.file(file_name, entry_file_name: 'text.txt') do |io|
25
25
  io.write(decompressed)
26
26
  end
27
- result = ::Zip::File.open(file_name) do |zip_file|
28
- zip_file.first.get_input_stream.read
29
- end
27
+ result = IOStreams::Zip::Reader.file(file_name, &:read)
30
28
  assert_equal decompressed, result
31
29
  end
32
30
 
@@ -36,14 +34,7 @@ class ZipWriterTest < Minitest::Test
36
34
  io.write(decompressed)
37
35
  end
38
36
  io = StringIO.new(io_string.string)
39
- result = nil
40
- begin
41
- zin = ::Zip::InputStream.new(io)
42
- zin.get_next_entry
43
- result = zin.read
44
- ensure
45
- zin.close if zin
46
- end
37
+ result = IOStreams::Zip::Reader.stream(io, &:read)
47
38
  assert_equal decompressed, result
48
39
  end
49
40
  end
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.0.0.beta5
4
+ version: 1.0.0.beta6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-20 00:00:00.000000000 Z
11
+ date: 2019-12-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: