iostreams 1.10.1 → 1.10.2
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 +0 -2
- data/lib/io_streams/pgp/writer.rb +3 -1
- data/lib/io_streams/record/reader.rb +0 -2
- data/lib/io_streams/row/reader.rb +0 -2
- 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/test/files/utf16_test.csv +0 -0
- data/test/line_reader_test.rb +0 -7
- data/test/paths/file_test.rb +0 -5
- data/test/record_reader_test.rb +0 -7
- data/test/row_reader_test.rb +0 -7
- data/test/tabular_test.rb +18 -0
- 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: 26d07bc98819ce065e8c698f00b75a6c2e9fc0a9ea6bf13c1afa8bc8c1e71e66
|
4
|
+
data.tar.gz: 2f7898b4197d3f94cbfcc30ba6c8d23e72121877833e57ec9a989e465d019ca2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
@@ -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
|
|
Binary file
|
data/test/line_reader_test.rb
CHANGED
@@ -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|
|
data/test/paths/file_test.rb
CHANGED
@@ -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
|
data/test/record_reader_test.rb
CHANGED
@@ -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
|
data/test/row_reader_test.rb
CHANGED
@@ -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.
|
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-
|
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
|