iostreams 1.9.0 → 1.10.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/io_streams/gzip/reader.rb +2 -2
- data/lib/io_streams/line/reader.rb +4 -3
- data/lib/io_streams/paths/file.rb +5 -0
- data/lib/io_streams/paths/s3.rb +5 -0
- data/lib/io_streams/paths/sftp.rb +5 -0
- data/lib/io_streams/pgp/writer.rb +3 -1
- data/lib/io_streams/tabular/parser/fixed.rb +2 -2
- data/lib/io_streams/version.rb +1 -1
- data/lib/io_streams/writer.rb +2 -1
- data/lib/io_streams/zip/writer.rb +6 -2
- data/test/bzip2_writer_test.rb +14 -8
- data/test/encode_writer_test.rb +19 -10
- data/test/files/utf16_test.csv +0 -0
- data/test/gzip_writer_test.rb +16 -8
- data/test/line_writer_test.rb +19 -9
- data/test/paths/file_test.rb +16 -1
- data/test/pgp_writer_test.rb +18 -9
- data/test/record_writer_test.rb +20 -10
- data/test/row_reader_test.rb +1 -1
- data/test/row_writer_test.rb +13 -7
- data/test/tabular_test.rb +18 -0
- data/test/zip_writer_test.rb +13 -7
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30ace4685022c88754654b2b48d1c86185e47841f1d3c6a3916bc348098b178d
|
4
|
+
data.tar.gz: 040c669d7ad4521941a3752dc405390c4f7dda98a583cc0f5d923091e12bd452
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90f2635d2e443fe4c4f3992d8f92a725118b2f52c0d4861ee1d778be8f145d93c2f0663904f8cf699b33106a154d13980634881a0039c7e0ad6389d137d69760
|
7
|
+
data.tar.gz: 970da1fd8e3b6ea7e1b36dad476c7f842413c2b8b50dc2939802b1962c00347bcdfa6a135245550c9cb639b694e9ca2c16439bde1afe7677701f3867cdc277e4
|
@@ -2,9 +2,9 @@ module IOStreams
|
|
2
2
|
module Gzip
|
3
3
|
class Reader < IOStreams::Reader
|
4
4
|
# Read from a gzip stream, decompressing the contents as it is read
|
5
|
-
def self.stream(input_stream, original_file_name: nil
|
5
|
+
def self.stream(input_stream, original_file_name: nil)
|
6
6
|
io = ::Zlib::GzipReader.new(input_stream)
|
7
|
-
|
7
|
+
yield io
|
8
8
|
ensure
|
9
9
|
io&.close
|
10
10
|
end
|
@@ -146,8 +146,8 @@ module IOStreams
|
|
146
146
|
data
|
147
147
|
end
|
148
148
|
|
149
|
-
# Returns
|
150
|
-
# Returns
|
149
|
+
# Returns whether more data is available to read
|
150
|
+
# Returns false on EOF
|
151
151
|
def read_block
|
152
152
|
return false if @eof
|
153
153
|
|
@@ -157,7 +157,8 @@ module IOStreams
|
|
157
157
|
@input_stream.read(@buffer_size, @read_cache_buffer)
|
158
158
|
rescue ArgumentError
|
159
159
|
# Handle arity of -1 when just 0..1
|
160
|
-
@read_cache_buffer
|
160
|
+
@read_cache_buffer = nil
|
161
|
+
@use_read_cache_buffer = false
|
161
162
|
@input_stream.read(@buffer_size)
|
162
163
|
end
|
163
164
|
else
|
@@ -89,6 +89,11 @@ module IOStreams
|
|
89
89
|
# "**.rb" "lib/song.rb" true
|
90
90
|
# "*" "dave/.profile" true
|
91
91
|
def each_child(pattern = "*", case_sensitive: false, directories: false, hidden: false)
|
92
|
+
unless block_given?
|
93
|
+
return to_enum(__method__, pattern,
|
94
|
+
case_sensitive: case_sensitive, directories: directories, hidden: hidden)
|
95
|
+
end
|
96
|
+
|
92
97
|
flags = 0
|
93
98
|
flags |= ::File::FNM_CASEFOLD unless case_sensitive
|
94
99
|
flags |= ::File::FNM_DOTMATCH if hidden
|
data/lib/io_streams/paths/s3.rb
CHANGED
@@ -284,6 +284,11 @@ module IOStreams
|
|
284
284
|
# Notes:
|
285
285
|
# - Currently all S3 lookups are recursive as of the pattern regardless of whether the pattern includes `**`.
|
286
286
|
def each_child(pattern = "*", case_sensitive: false, directories: false, hidden: false)
|
287
|
+
unless block_given?
|
288
|
+
return to_enum(__method__, pattern,
|
289
|
+
case_sensitive: case_sensitive, directories: directories, hidden: hidden)
|
290
|
+
end
|
291
|
+
|
287
292
|
matcher = Matcher.new(self, pattern, case_sensitive: case_sensitive, hidden: hidden)
|
288
293
|
|
289
294
|
# When the pattern includes an exact file name without any pattern characters
|
@@ -142,6 +142,11 @@ module IOStreams
|
|
142
142
|
# sftp://sftp.example.org/a/b/c/test.txt {:type=>1, :size=>37, :owner=>"test_owner", :group=>"test_group",
|
143
143
|
# :permissions=>420, :atime=>1572378136, :mtime=>1572378136, :link_count=>1, :extended=>{}}
|
144
144
|
def each_child(pattern = "*", case_sensitive: true, directories: false, hidden: false)
|
145
|
+
unless block_given?
|
146
|
+
return to_enum(__method__, pattern,
|
147
|
+
case_sensitive: case_sensitive, directories: directories, hidden: hidden)
|
148
|
+
end
|
149
|
+
|
145
150
|
Utils.load_soft_dependency("net-sftp", "SFTP glob capability", "net/sftp") unless defined?(Net::SFTP)
|
146
151
|
|
147
152
|
flags = ::File::FNM_EXTGLOB
|
@@ -89,10 +89,11 @@ module IOStreams
|
|
89
89
|
|
90
90
|
IOStreams::Pgp.logger&.debug { "IOStreams::Pgp::Writer.open: #{command}" }
|
91
91
|
|
92
|
+
result = nil
|
92
93
|
Open3.popen2e(command) do |stdin, out, waith_thr|
|
93
94
|
begin
|
94
95
|
stdin.binmode
|
95
|
-
yield(stdin)
|
96
|
+
result = yield(stdin)
|
96
97
|
stdin.close
|
97
98
|
rescue Errno::EPIPE
|
98
99
|
# Ignore broken pipe because gpg terminates early due to an error
|
@@ -104,6 +105,7 @@ module IOStreams
|
|
104
105
|
raise(Pgp::Failure, "GPG Failed to create encrypted file: #{file_name}: #{out.read.chomp}")
|
105
106
|
end
|
106
107
|
end
|
108
|
+
result
|
107
109
|
end
|
108
110
|
end
|
109
111
|
end
|
@@ -148,14 +148,14 @@ module IOStreams
|
|
148
148
|
|
149
149
|
def initialize(size:, key: nil, type: :string, decimals: 2)
|
150
150
|
@key = key
|
151
|
-
@size = size == :remainder ? -1 : size.to_i
|
151
|
+
@size = (size == :remainder || size == "remainder") ? -1 : size.to_i
|
152
152
|
@type = type.to_sym
|
153
153
|
@decimals = decimals
|
154
154
|
|
155
155
|
unless @size.positive? || (@size == -1)
|
156
156
|
raise(Errors::InvalidLayout, "Size #{size.inspect} must be positive or :remainder")
|
157
157
|
end
|
158
|
-
raise(Errors::InvalidLayout, "Unknown type: #{type.inspect}") unless TYPES.include?(type)
|
158
|
+
raise(Errors::InvalidLayout, "Unknown type: #{type.inspect}") unless TYPES.include?(@type)
|
159
159
|
end
|
160
160
|
|
161
161
|
def parse(value)
|
data/lib/io_streams/version.rb
CHANGED
data/lib/io_streams/writer.rb
CHANGED
@@ -4,8 +4,9 @@ module IOStreams
|
|
4
4
|
# and then pass that filename in for this reader.
|
5
5
|
def self.stream(output_stream, original_file_name: nil, **args, &block)
|
6
6
|
Utils.temp_file_name("iostreams_writer") do |file_name|
|
7
|
-
file(file_name, original_file_name: original_file_name, **args, &block)
|
7
|
+
count = file(file_name, original_file_name: original_file_name, **args, &block)
|
8
8
|
::File.open(file_name, "rb") { |source| ::IO.copy_stream(source, output_stream) }
|
9
|
+
count
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
@@ -14,7 +14,7 @@ module IOStreams
|
|
14
14
|
# Name of the file entry within the Zip file.
|
15
15
|
#
|
16
16
|
# The stream supplied to the block only responds to #write
|
17
|
-
def self.stream(output_stream, original_file_name: nil, zip_file_name: nil, entry_file_name: zip_file_name
|
17
|
+
def self.stream(output_stream, original_file_name: nil, zip_file_name: nil, entry_file_name: zip_file_name)
|
18
18
|
# Default the name of the file within the zip to the supplied file_name without the zip extension
|
19
19
|
if entry_file_name.nil? && original_file_name && (original_file_name =~ /\.(zip)\z/i)
|
20
20
|
entry_file_name = original_file_name.to_s[0..-5]
|
@@ -23,7 +23,11 @@ module IOStreams
|
|
23
23
|
|
24
24
|
Utils.load_soft_dependency("zip_tricks", "Zip") unless defined?(ZipTricks::Streamer)
|
25
25
|
|
26
|
-
|
26
|
+
result = nil
|
27
|
+
ZipTricks::Streamer.open(output_stream) do |zip|
|
28
|
+
zip.write_deflated_file(entry_file_name) { |io| result = yield(io) }
|
29
|
+
end
|
30
|
+
result
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
data/test/bzip2_writer_test.rb
CHANGED
@@ -20,10 +20,13 @@ class Bzip2WriterTest < Minitest::Test
|
|
20
20
|
|
21
21
|
describe ".file" do
|
22
22
|
it "file" do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
result =
|
24
|
+
IOStreams::Bzip2::Writer.file(file_name) do |io|
|
25
|
+
io.write(decompressed)
|
26
|
+
io.write(decompressed)
|
27
|
+
53534
|
28
|
+
end
|
29
|
+
assert_equal 53534, result
|
27
30
|
|
28
31
|
File.open(file_name, "rb") do |file|
|
29
32
|
io = ::Bzip2::FFI::Reader.new(file)
|
@@ -35,10 +38,13 @@ class Bzip2WriterTest < Minitest::Test
|
|
35
38
|
|
36
39
|
it "stream" do
|
37
40
|
io_string = StringIO.new("".b)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
result =
|
42
|
+
IOStreams::Bzip2::Writer.stream(io_string) do |io|
|
43
|
+
io.write(decompressed)
|
44
|
+
io.write(decompressed)
|
45
|
+
53534
|
46
|
+
end
|
47
|
+
assert_equal 53534, result
|
42
48
|
|
43
49
|
io = StringIO.new(io_string.string)
|
44
50
|
rbzip2 = ::Bzip2::FFI::Reader.new(io)
|
data/test/encode_writer_test.rb
CHANGED
@@ -22,18 +22,24 @@ class EncodeWriterTest < Minitest::Test
|
|
22
22
|
it "file" do
|
23
23
|
temp_file = Tempfile.new("rocket_job")
|
24
24
|
file_name = temp_file.to_path
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
result =
|
26
|
+
IOStreams::Encode::Writer.file(file_name, encoding: "ASCII-8BIT") do |io|
|
27
|
+
io << bad_data
|
28
|
+
53534
|
29
|
+
end
|
30
|
+
assert_equal 53534, result
|
28
31
|
result = File.read(file_name, mode: "rb")
|
29
32
|
assert_equal bad_data, result
|
30
33
|
end
|
31
34
|
|
32
35
|
it "stream" do
|
33
|
-
io
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
io = StringIO.new("".b)
|
37
|
+
result =
|
38
|
+
IOStreams::Encode::Writer.stream(io, encoding: "ASCII-8BIT") do |encoded|
|
39
|
+
encoded << bad_data
|
40
|
+
53534
|
41
|
+
end
|
42
|
+
assert_equal 53534, result
|
37
43
|
assert_equal "ASCII-8BIT", io.string.encoding.to_s
|
38
44
|
assert_equal bad_data, io.string
|
39
45
|
end
|
@@ -70,9 +76,12 @@ class EncodeWriterTest < Minitest::Test
|
|
70
76
|
it "returns byte count" do
|
71
77
|
io_string = StringIO.new("".b)
|
72
78
|
count = 0
|
73
|
-
|
74
|
-
|
75
|
-
|
79
|
+
result =
|
80
|
+
IOStreams::Encode::Writer.stream(io_string, encoding: "ASCII-8BIT") do |io|
|
81
|
+
count += io.write(bad_data)
|
82
|
+
53534
|
83
|
+
end
|
84
|
+
assert_equal 53534, result
|
76
85
|
assert_equal bad_data, io_string.string
|
77
86
|
assert_equal bad_data.size, count
|
78
87
|
end
|
Binary file
|
data/test/gzip_writer_test.rb
CHANGED
@@ -20,9 +20,13 @@ class GzipWriterTest < Minitest::Test
|
|
20
20
|
|
21
21
|
describe ".file" do
|
22
22
|
it "file" do
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
result =
|
24
|
+
IOStreams::Gzip::Writer.file(file_name) do |io|
|
25
|
+
io.write(decompressed)
|
26
|
+
53534
|
27
|
+
end
|
28
|
+
assert_equal 53534, result
|
29
|
+
|
26
30
|
result = Zlib::GzipReader.open(file_name, &:read)
|
27
31
|
temp_file.delete
|
28
32
|
assert_equal decompressed, result
|
@@ -30,11 +34,15 @@ class GzipWriterTest < Minitest::Test
|
|
30
34
|
|
31
35
|
it "stream" do
|
32
36
|
io_string = StringIO.new("".b)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
37
|
+
result =
|
38
|
+
IOStreams::Gzip::Writer.stream(io_string) do |io|
|
39
|
+
io.write(decompressed)
|
40
|
+
53534
|
41
|
+
end
|
42
|
+
assert_equal 53534, result
|
43
|
+
|
44
|
+
io = StringIO.new(io_string.string)
|
45
|
+
gz = Zlib::GzipReader.new(io)
|
38
46
|
data = gz.read
|
39
47
|
gz.close
|
40
48
|
assert_equal decompressed, data
|
data/test/line_writer_test.rb
CHANGED
@@ -18,18 +18,25 @@ class DelimitedWriterTest < Minitest::Test
|
|
18
18
|
it "file" do
|
19
19
|
temp_file = Tempfile.new("rocket_job")
|
20
20
|
file_name = temp_file.to_path
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
result =
|
22
|
+
IOStreams::Line::Writer.file(file_name) do |io|
|
23
|
+
lines.each { |line| io << line }
|
24
|
+
53534
|
25
|
+
end
|
26
|
+
assert_equal 53534, result
|
27
|
+
|
24
28
|
result = File.read(file_name)
|
25
29
|
assert_equal raw, result
|
26
30
|
end
|
27
31
|
|
28
32
|
it "stream" do
|
29
33
|
io_string = StringIO.new
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
result =
|
35
|
+
IOStreams::Line::Writer.stream(io_string) do |io|
|
36
|
+
lines.each { |line| io << line }
|
37
|
+
53534
|
38
|
+
end
|
39
|
+
assert_equal 53534, result
|
33
40
|
assert_equal raw, io_string.string
|
34
41
|
end
|
35
42
|
end
|
@@ -38,9 +45,12 @@ class DelimitedWriterTest < Minitest::Test
|
|
38
45
|
it "returns byte count" do
|
39
46
|
io_string = StringIO.new
|
40
47
|
count = 0
|
41
|
-
|
42
|
-
|
43
|
-
|
48
|
+
result =
|
49
|
+
IOStreams::Line::Writer.stream(io_string) do |io|
|
50
|
+
lines.each { |line| count += io.write(line) }
|
51
|
+
53534
|
52
|
+
end
|
53
|
+
assert_equal 53534, result
|
44
54
|
assert_equal raw, io_string.string
|
45
55
|
assert_equal raw.size, count
|
46
56
|
end
|
data/test/paths/file_test.rb
CHANGED
@@ -5,7 +5,7 @@ module Paths
|
|
5
5
|
describe IOStreams::Paths::File do
|
6
6
|
let(:root) { IOStreams::Paths::File.new("/tmp/iostreams").delete_all }
|
7
7
|
let(:directory) { root.join("/some_test_dir") }
|
8
|
-
let(:data) { "Hello World" }
|
8
|
+
let(:data) { "Hello World\nHow are you doing?\nOn this fine day" }
|
9
9
|
let(:file_path) do
|
10
10
|
path = root.join("some_test_dir/test_file.txt")
|
11
11
|
path.writer { |io| io << data }
|
@@ -17,6 +17,15 @@ module Paths
|
|
17
17
|
path
|
18
18
|
end
|
19
19
|
|
20
|
+
describe "#each" do
|
21
|
+
it "reads lines" do
|
22
|
+
records = []
|
23
|
+
count = file_path.each { |line| records << line }
|
24
|
+
assert_equal count, data.lines.size
|
25
|
+
assert_equal data.lines.collect(&:strip), records
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
20
29
|
describe "#each_child" do
|
21
30
|
it "iterates an empty path" do
|
22
31
|
none = nil
|
@@ -48,6 +57,12 @@ module Paths
|
|
48
57
|
actual = root.children("**/Test*.TXT", case_sensitive: true).collect(&:to_s)
|
49
58
|
refute_equal expected, actual.sort
|
50
59
|
end
|
60
|
+
|
61
|
+
it "with no block returns enumerator" do
|
62
|
+
expected = [file_path.to_s, file_path2.to_s]
|
63
|
+
actual = root.each_child("**/*").first(100).collect(&:to_s)
|
64
|
+
assert_equal expected.sort, actual.sort
|
65
|
+
end
|
51
66
|
end
|
52
67
|
|
53
68
|
describe "#mkpath" do
|
data/test/pgp_writer_test.rb
CHANGED
@@ -21,9 +21,12 @@ class PgpWriterTest < Minitest::Test
|
|
21
21
|
|
22
22
|
describe ".file" do
|
23
23
|
it "writes encrypted text file" do
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
result =
|
25
|
+
IOStreams::Pgp::Writer.file(file_name, recipient: "receiver@example.org") do |io|
|
26
|
+
io.write(decrypted)
|
27
|
+
53534
|
28
|
+
end
|
29
|
+
assert_equal 53534, result
|
27
30
|
|
28
31
|
result = IOStreams::Pgp::Reader.file(file_name, passphrase: "receiver_passphrase", &:read)
|
29
32
|
assert_equal decrypted, result
|
@@ -34,9 +37,12 @@ class PgpWriterTest < Minitest::Test
|
|
34
37
|
binary_data = File.open(binary_file_name, "rb", &:read)
|
35
38
|
|
36
39
|
File.open(binary_file_name, "rb") do |input|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
result =
|
41
|
+
IOStreams::Pgp::Writer.file(file_name, recipient: "receiver@example.org") do |output|
|
42
|
+
IO.copy_stream(input, output)
|
43
|
+
53534
|
44
|
+
end
|
45
|
+
assert_equal 53534, result
|
40
46
|
end
|
41
47
|
|
42
48
|
result = IOStreams::Pgp::Reader.file(file_name, passphrase: "receiver_passphrase", &:read)
|
@@ -108,9 +114,12 @@ class PgpWriterTest < Minitest::Test
|
|
108
114
|
|
109
115
|
it "writes to a stream" do
|
110
116
|
io_string = StringIO.new("".b)
|
111
|
-
|
112
|
-
|
113
|
-
|
117
|
+
result =
|
118
|
+
IOStreams::Pgp::Writer.stream(io_string, recipient: "receiver@example.org", signer: "sender@example.org", signer_passphrase: "sender_passphrase") do |io|
|
119
|
+
io.write(decrypted)
|
120
|
+
53534
|
121
|
+
end
|
122
|
+
assert_equal 53534, result
|
114
123
|
|
115
124
|
io = StringIO.new(io_string.string)
|
116
125
|
result = IOStreams::Pgp::Reader.stream(io, passphrase: "receiver_passphrase", &:read)
|
data/test/record_writer_test.rb
CHANGED
@@ -43,28 +43,38 @@ class RecordWriterTest < Minitest::Test
|
|
43
43
|
|
44
44
|
describe "#<<" do
|
45
45
|
it "file" do
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
result =
|
47
|
+
IOStreams::Record::Writer.file(file_name) do |io|
|
48
|
+
inputs.each { |hash| io << hash }
|
49
|
+
53534
|
50
|
+
end
|
51
|
+
assert_equal 53534, result
|
49
52
|
result = File.read(file_name)
|
50
53
|
assert_equal raw_csv_data, result
|
51
54
|
end
|
52
55
|
|
53
56
|
it "json file" do
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
result =
|
58
|
+
IOStreams::Record::Writer.file(file_name, file_name: "abc.json") do |io|
|
59
|
+
inputs.each { |hash| io << hash }
|
60
|
+
53534
|
61
|
+
end
|
62
|
+
assert_equal 53534, result
|
63
|
+
|
57
64
|
result = File.read(file_name)
|
58
65
|
assert_equal raw_json_data, result
|
59
66
|
end
|
60
67
|
|
61
68
|
it "stream" do
|
62
69
|
io_string = StringIO.new
|
63
|
-
|
64
|
-
IOStreams::
|
65
|
-
|
70
|
+
result =
|
71
|
+
IOStreams::Line::Writer.stream(io_string) do |io|
|
72
|
+
IOStreams::Record::Writer.stream(io) do |stream|
|
73
|
+
inputs.each { |row| stream << row }
|
74
|
+
53534
|
75
|
+
end
|
66
76
|
end
|
67
|
-
|
77
|
+
assert_equal 53534, result
|
68
78
|
assert_equal raw_csv_data, io_string.string
|
69
79
|
end
|
70
80
|
end
|
data/test/row_reader_test.rb
CHANGED
data/test/row_writer_test.rb
CHANGED
@@ -29,20 +29,26 @@ class RowWriterTest < Minitest::Test
|
|
29
29
|
|
30
30
|
describe ".stream" do
|
31
31
|
it "file" do
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
result =
|
33
|
+
IOStreams::Row::Writer.file(file_name) do |io|
|
34
|
+
csv_rows.each { |array| io << array }
|
35
|
+
53534
|
36
|
+
end
|
37
|
+
assert_equal 53534, result
|
35
38
|
result = ::File.read(file_name)
|
36
39
|
assert_equal raw_csv_data, result
|
37
40
|
end
|
38
41
|
|
39
42
|
it "streams" do
|
40
43
|
io_string = StringIO.new
|
41
|
-
|
42
|
-
IOStreams::
|
43
|
-
|
44
|
+
result =
|
45
|
+
IOStreams::Line::Writer.stream(io_string) do |io|
|
46
|
+
IOStreams::Row::Writer.stream(io) do |stream|
|
47
|
+
csv_rows.each { |array| stream << array }
|
48
|
+
53534
|
49
|
+
end
|
44
50
|
end
|
45
|
-
|
51
|
+
assert_equal 53534, result
|
46
52
|
assert_equal raw_csv_data, io_string.string
|
47
53
|
end
|
48
54
|
end
|
data/test/tabular_test.rb
CHANGED
@@ -40,6 +40,19 @@ class TabularTest < Minitest::Test
|
|
40
40
|
IOStreams::Tabular.new(format: :fixed, format_options: {layout: layout})
|
41
41
|
end
|
42
42
|
|
43
|
+
let :fixed_with_strings do
|
44
|
+
layout = [
|
45
|
+
{size: "23", key: "name"},
|
46
|
+
{size: 40, key: "address"},
|
47
|
+
{size: 2},
|
48
|
+
{size: 5.0, key: "zip", type: "integer"},
|
49
|
+
{size: "8", key: "age", type: "integer"},
|
50
|
+
{size: 10, key: "weight", type: "float", decimals: 2},
|
51
|
+
{size: "remainder", key: "remainder"}
|
52
|
+
]
|
53
|
+
IOStreams::Tabular.new(format: :fixed, format_options: {layout: layout})
|
54
|
+
end
|
55
|
+
|
43
56
|
describe "#parse_header" do
|
44
57
|
it "parses and sets the csv header" do
|
45
58
|
tabular = IOStreams::Tabular.new(format: :csv)
|
@@ -269,6 +282,11 @@ class TabularTest < Minitest::Test
|
|
269
282
|
assert_equal "Jack over there 34618000000210123456.79", string
|
270
283
|
end
|
271
284
|
|
285
|
+
it "renders fixed data with string keys" do
|
286
|
+
assert string = fixed_with_strings.render("name" => "Jack", "address" => "over there", "zip" => 34_618, "weight" => 123_456.789123, "age" => 21)
|
287
|
+
assert_equal "Jack over there 34618000000210123456.79", string
|
288
|
+
end
|
289
|
+
|
272
290
|
it "truncates long strings" do
|
273
291
|
assert string = fixed.render(name: "Jack ran up the beanstalk and when jack reached the top it was truncated", address: "over there", zip: 34_618)
|
274
292
|
assert_equal "Jack ran up the beanstaover there 34618000000000000000.00", string
|
data/test/zip_writer_test.rb
CHANGED
@@ -21,19 +21,25 @@ class ZipWriterTest < Minitest::Test
|
|
21
21
|
|
22
22
|
describe ".file" do
|
23
23
|
it "file" do
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
result =
|
25
|
+
IOStreams::Zip::Writer.file(file_name, entry_file_name: "text.txt") do |io|
|
26
|
+
io.write(decompressed)
|
27
|
+
53534
|
28
|
+
end
|
29
|
+
assert_equal 53534, result
|
27
30
|
result = IOStreams::Zip::Reader.file(file_name, &:read)
|
28
31
|
assert_equal decompressed, result
|
29
32
|
end
|
30
33
|
|
31
34
|
it "stream" do
|
32
35
|
io_string = StringIO.new("".b)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
36
|
+
result =
|
37
|
+
IOStreams::Zip::Writer.stream(io_string) do |io|
|
38
|
+
io.write(decompressed)
|
39
|
+
53534
|
40
|
+
end
|
41
|
+
assert_equal 53534, result
|
42
|
+
io = StringIO.new(io_string.string)
|
37
43
|
result = IOStreams::Zip::Reader.stream(io, &:read)
|
38
44
|
assert_equal decompressed, result
|
39
45
|
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.
|
4
|
+
version: 1.10.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: 2021-
|
11
|
+
date: 2021-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- test/files/unclosed_quote_large_test.csv
|
88
88
|
- test/files/unclosed_quote_test.csv
|
89
89
|
- test/files/unclosed_quote_test2.csv
|
90
|
+
- test/files/utf16_test.csv
|
90
91
|
- test/gzip_reader_test.rb
|
91
92
|
- test/gzip_writer_test.rb
|
92
93
|
- test/io_streams_test.rb
|
@@ -159,6 +160,7 @@ test_files:
|
|
159
160
|
- test/files/unclosed_quote_large_test.csv
|
160
161
|
- test/files/unclosed_quote_test.csv
|
161
162
|
- test/files/unclosed_quote_test2.csv
|
163
|
+
- test/files/utf16_test.csv
|
162
164
|
- test/gzip_reader_test.rb
|
163
165
|
- test/gzip_writer_test.rb
|
164
166
|
- test/io_streams_test.rb
|