iostreams 1.10.1 → 1.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c93dac4c226c66c4e36554311858ff328299fc4202c257cdb0e7f2c8e82e323b
4
- data.tar.gz: fa96f9d6007769b812ab5506e1ca5ca20866ed9d6fc6bc98d75b50a0d50a23b2
3
+ metadata.gz: 26d07bc98819ce065e8c698f00b75a6c2e9fc0a9ea6bf13c1afa8bc8c1e71e66
4
+ data.tar.gz: 2f7898b4197d3f94cbfcc30ba6c8d23e72121877833e57ec9a989e465d019ca2
5
5
  SHA512:
6
- metadata.gz: 2538af2be40ad81287b4c3501f0ff9672ea82289adcb2de1e976d868fd9aa655f01d496b6299ba851193e1ed832750e6bcb21f6ed88179aab303f348e4bef60f
7
- data.tar.gz: e7d6c8f09d0377f0bdfb83fdfc61559afd1581d1e8425cc9a3a76754be2e92003f202246c0a43b83b12107774965388aa71f2c2950835797363ce057ca5fe24b
6
+ metadata.gz: 2887fb5b2935d28bcf2426fd7139a6b7a27c87c1da8d7289cc69f0a644c2d98e4667f6e6da1a57133bcf8bdd93e948d7819d24ce09cb0d65f6c35d59b0b604c7
7
+ data.tar.gz: 034aa07ff80107a139dd86ffd492361887de4f4e8190385b48d12b1bedeb0a3af8c1a25720d41f731330cb46d707736972c707c3ec5576551425d29d3843da68
@@ -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, &block)
5
+ def self.stream(input_stream, original_file_name: nil)
6
6
  io = ::Zlib::GzipReader.new(input_stream)
7
- block.call(io)
7
+ yield io
8
8
  ensure
9
9
  io&.close
10
10
  end
@@ -75,8 +75,6 @@ module IOStreams
75
75
  # Note:
76
76
  # * The line delimiter is _not_ returned.
77
77
  def each
78
- return to_enum(__method__) unless block_given?
79
-
80
78
  line_count = 0
81
79
  until eof?
82
80
  line = readline
@@ -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
@@ -68,8 +68,6 @@ module IOStreams
68
68
  end
69
69
 
70
70
  def each
71
- return to_enum(__method__) unless block_given?
72
-
73
71
  @line_reader.each do |line|
74
72
  if @tabular.header?
75
73
  @tabular.parse_header(line)
@@ -40,8 +40,6 @@ module IOStreams
40
40
  end
41
41
 
42
42
  def each
43
- return to_enum(__method__) unless block_given?
44
-
45
43
  @line_reader.each do |line|
46
44
  if @tabular.header?
47
45
  columns = @tabular.parse_header(line)
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module IOStreams
2
- VERSION = "1.10.1".freeze
2
+ VERSION = "1.10.2".freeze
3
3
  end
@@ -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
 
Binary file
@@ -98,13 +98,6 @@ class LineReaderTest < Minitest::Test
98
98
  assert_equal data.size, count
99
99
  end
100
100
 
101
- it "with no block returns enumerator" do
102
- lines = IOStreams::Line::Reader.file(file_name) do |io|
103
- io.each.first(100)
104
- end
105
- assert_equal data, lines
106
- end
107
-
108
101
  it "each_line stream" do
109
102
  lines = []
110
103
  count = File.open(file_name) do |file|
@@ -24,11 +24,6 @@ module Paths
24
24
  assert_equal count, data.lines.size
25
25
  assert_equal data.lines.collect(&:strip), records
26
26
  end
27
-
28
- it "reads lines without block" do
29
- records = file_path.each.first(100)
30
- assert_equal data.lines.collect(&:strip), records
31
- end
32
27
  end
33
28
 
34
29
  describe "#each_child" do
@@ -46,13 +46,6 @@ class RecordReaderTest < Minitest::Test
46
46
  end
47
47
  assert_equal expected, rows
48
48
  end
49
-
50
- it "with no block returns enumerator" do
51
- records = IOStreams::Record::Reader.file(file_name, cleanse_header: false) do |io|
52
- io.each.first(100)
53
- end
54
- assert_equal expected, records
55
- end
56
49
  end
57
50
 
58
51
  describe "#collect" do
@@ -20,13 +20,6 @@ class RowReaderTest < Minitest::Test
20
20
  assert_equal expected.size, count
21
21
  end
22
22
 
23
- it "with no block returns enumerator" do
24
- rows = IOStreams::Row::Reader.file(file_name) do |io|
25
- io.each.first(100)
26
- end
27
- assert_equal expected, rows
28
- end
29
-
30
23
  it "stream" do
31
24
  rows = []
32
25
  count = IOStreams::Line::Reader.file(file_name) do |file|
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
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.10.1
4
+ version: 1.10.2
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-08-30 00:00:00.000000000 Z
11
+ date: 2021-10-25 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