iostreams 1.11.0 → 2.0.0
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 +4 -4
- data/README.md +20 -2
- data/Rakefile +7 -0
- data/lib/io_streams/builder.rb +9 -9
- data/lib/io_streams/bzip2/writer.rb +1 -1
- data/lib/io_streams/encode/reader.rb +2 -2
- data/lib/io_streams/encode/writer.rb +5 -5
- data/lib/io_streams/gzip/reader.rb +1 -1
- data/lib/io_streams/gzip/writer.rb +1 -1
- data/lib/io_streams/io_streams.rb +45 -19
- data/lib/io_streams/line/reader.rb +2 -2
- data/lib/io_streams/line/writer.rb +1 -1
- data/lib/io_streams/path.rb +2 -2
- data/lib/io_streams/paths/file.rb +10 -10
- data/lib/io_streams/paths/http.rb +80 -7
- data/lib/io_streams/paths/matcher.rb +3 -3
- data/lib/io_streams/paths/s3.rb +3 -3
- data/lib/io_streams/paths/sftp.rb +7 -8
- data/lib/io_streams/pgp/reader.rb +23 -10
- data/lib/io_streams/pgp/writer.rb +93 -32
- data/lib/io_streams/pgp.rb +188 -60
- data/lib/io_streams/reader.rb +4 -4
- data/lib/io_streams/record/reader.rb +3 -4
- data/lib/io_streams/record/writer.rb +3 -4
- data/lib/io_streams/row/reader.rb +1 -1
- data/lib/io_streams/row/writer.rb +1 -1
- data/lib/io_streams/stream.rb +36 -30
- data/lib/io_streams/symmetric_encryption/reader.rb +2 -2
- data/lib/io_streams/symmetric_encryption/writer.rb +4 -4
- data/lib/io_streams/tabular/header.rb +18 -6
- data/lib/io_streams/tabular/parser/array.rb +0 -10
- data/lib/io_streams/tabular/parser/csv.rb +6 -38
- data/lib/io_streams/tabular/parser/fixed.rb +5 -5
- data/lib/io_streams/tabular/parser/psv.rb +0 -12
- data/lib/io_streams/tabular.rb +5 -10
- data/lib/io_streams/utils.rb +3 -2
- data/lib/io_streams/version.rb +1 -1
- data/lib/io_streams/writer.rb +6 -6
- data/lib/io_streams/xlsx/reader.rb +1 -1
- data/lib/io_streams/zip/writer.rb +22 -10
- data/lib/iostreams.rb +0 -1
- metadata +28 -111
- data/lib/io_streams/deprecated.rb +0 -216
- data/lib/io_streams/tabular/utility/csv_row.rb +0 -105
- data/test/builder_test.rb +0 -311
- data/test/bzip2_reader_test.rb +0 -27
- data/test/bzip2_writer_test.rb +0 -56
- data/test/deprecated_test.rb +0 -121
- data/test/encode_reader_test.rb +0 -51
- data/test/encode_writer_test.rb +0 -90
- data/test/files/embedded_lines_test.csv +0 -7
- data/test/files/multiple_files.zip +0 -0
- data/test/files/spreadsheet.xlsx +0 -0
- data/test/files/test.csv +0 -4
- data/test/files/test.json +0 -3
- data/test/files/test.psv +0 -4
- data/test/files/text file.txt +0 -3
- data/test/files/text.txt +0 -3
- data/test/files/text.txt.bz2 +0 -0
- data/test/files/text.txt.gz +0 -0
- data/test/files/text.txt.gz.zip +0 -0
- data/test/files/text.zip +0 -0
- data/test/files/text.zip.gz +0 -0
- data/test/files/unclosed_quote_large_test.csv +0 -1658
- data/test/files/unclosed_quote_test.csv +0 -4
- data/test/files/unclosed_quote_test2.csv +0 -3
- data/test/gzip_reader_test.rb +0 -27
- data/test/gzip_writer_test.rb +0 -52
- data/test/io_streams_test.rb +0 -132
- data/test/line_reader_test.rb +0 -325
- data/test/line_writer_test.rb +0 -59
- data/test/minimal_file_reader.rb +0 -25
- data/test/path_test.rb +0 -55
- data/test/paths/file_test.rb +0 -213
- data/test/paths/http_test.rb +0 -34
- data/test/paths/matcher_test.rb +0 -120
- data/test/paths/s3_test.rb +0 -220
- data/test/paths/sftp_test.rb +0 -106
- data/test/pgp_reader_test.rb +0 -46
- data/test/pgp_test.rb +0 -267
- data/test/pgp_writer_test.rb +0 -130
- data/test/record_reader_test.rb +0 -60
- data/test/record_writer_test.rb +0 -82
- data/test/row_reader_test.rb +0 -35
- data/test/row_writer_test.rb +0 -56
- data/test/stream_test.rb +0 -577
- data/test/tabular_test.rb +0 -338
- data/test/test_helper.rb +0 -40
- data/test/utils_test.rb +0 -20
- data/test/xlsx_reader_test.rb +0 -37
- data/test/zip_reader_test.rb +0 -53
- data/test/zip_writer_test.rb +0 -48
data/test/bzip2_writer_test.rb
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
require_relative "test_helper"
|
|
2
|
-
|
|
3
|
-
class Bzip2WriterTest < Minitest::Test
|
|
4
|
-
describe IOStreams::Bzip2::Writer do
|
|
5
|
-
let :temp_file do
|
|
6
|
-
Tempfile.new("iostreams")
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
let :file_name do
|
|
10
|
-
temp_file.path
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
let :decompressed do
|
|
14
|
-
File.read(File.join(File.dirname(__FILE__), "files", "text.txt"))
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
after do
|
|
18
|
-
temp_file.delete
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe ".file" do
|
|
22
|
-
it "file" do
|
|
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
|
|
30
|
-
|
|
31
|
-
File.open(file_name, "rb") do |file|
|
|
32
|
-
io = ::Bzip2::FFI::Reader.new(file)
|
|
33
|
-
result = io.read
|
|
34
|
-
temp_file.delete
|
|
35
|
-
assert_equal decompressed + decompressed, result
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it "stream" do
|
|
40
|
-
io_string = StringIO.new("".b)
|
|
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
|
|
48
|
-
|
|
49
|
-
io = StringIO.new(io_string.string)
|
|
50
|
-
rbzip2 = ::Bzip2::FFI::Reader.new(io)
|
|
51
|
-
data = rbzip2.read
|
|
52
|
-
assert_equal decompressed + decompressed, data
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
data/test/deprecated_test.rb
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
require_relative "test_helper"
|
|
2
|
-
|
|
3
|
-
IOStreams.include(IOStreams::Deprecated)
|
|
4
|
-
|
|
5
|
-
# Test deprecated api
|
|
6
|
-
class DeprecatedTest < Minitest::Test
|
|
7
|
-
describe IOStreams do
|
|
8
|
-
let :source_file_name do
|
|
9
|
-
File.join(__dir__, "files", "text.txt")
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
let :data do
|
|
13
|
-
File.read(source_file_name)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
let :temp_file do
|
|
17
|
-
Tempfile.new("iostreams")
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
let :target_file_name do
|
|
21
|
-
temp_file.path
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
let :bad_data do
|
|
25
|
-
[
|
|
26
|
-
"New M\xE9xico,NE".b,
|
|
27
|
-
"good line",
|
|
28
|
-
"New M\xE9xico,\x07SF".b
|
|
29
|
-
].join("\n").encode("BINARY")
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
let :stripped_data do
|
|
33
|
-
bad_data.gsub("\xE9".b, "").gsub("\x07", "")
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
let :multiple_zip_file_name do
|
|
37
|
-
File.join(File.dirname(__FILE__), "files", "multiple_files.zip")
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
let :zip_gz_file_name do
|
|
41
|
-
File.join(File.dirname(__FILE__), "files", "text.zip.gz")
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
let :contents_test_txt do
|
|
45
|
-
File.read(File.join(File.dirname(__FILE__), "files", "text.txt"))
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
let :contents_test_json do
|
|
49
|
-
File.read(File.join(File.dirname(__FILE__), "files", "test.json"))
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
after do
|
|
53
|
-
temp_file.delete
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
describe ".copy" do
|
|
57
|
-
it "streams" do
|
|
58
|
-
size = IOStreams.reader(source_file_name) do |source_stream|
|
|
59
|
-
IOStreams.writer(target_file_name) do |target_stream|
|
|
60
|
-
IOStreams.copy(source_stream, target_stream)
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
actual = File.read(target_file_name)
|
|
64
|
-
|
|
65
|
-
assert_equal actual, data
|
|
66
|
-
assert_equal actual.size, size
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it "IO stream" do
|
|
70
|
-
size = File.open(source_file_name) do |source_stream|
|
|
71
|
-
IOStreams.writer(target_file_name) do |target_stream|
|
|
72
|
-
IOStreams.copy(source_stream, target_stream)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
actual = File.read(target_file_name)
|
|
76
|
-
|
|
77
|
-
assert_equal actual, data
|
|
78
|
-
assert_equal actual.size, size
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "files" do
|
|
82
|
-
size = IOStreams.copy(source_file_name, target_file_name)
|
|
83
|
-
actual = File.read(target_file_name)
|
|
84
|
-
|
|
85
|
-
assert_equal actual, data
|
|
86
|
-
assert_equal actual.size, size
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
describe ".each_line" do
|
|
91
|
-
it "returns a line at a time" do
|
|
92
|
-
lines = []
|
|
93
|
-
count = IOStreams.each_line(source_file_name) { |line| lines << line }
|
|
94
|
-
assert_equal data.lines.map(&:strip), lines
|
|
95
|
-
assert_equal data.lines.count, count
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it "strips non-printable characters" do
|
|
99
|
-
input = StringIO.new(bad_data)
|
|
100
|
-
lines = []
|
|
101
|
-
count = IOStreams.each_line(input, encoding: "UTF-8", encode_cleaner: :printable, encode_replace: "") do |line|
|
|
102
|
-
lines << line
|
|
103
|
-
end
|
|
104
|
-
assert_equal stripped_data.lines.map(&:strip), lines
|
|
105
|
-
assert_equal stripped_data.lines.count, count
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
describe ".reader" do
|
|
110
|
-
it "reads a zip file" do
|
|
111
|
-
result = IOStreams.reader(multiple_zip_file_name, streams: {zip: {entry_file_name: "test.json"}}, &:read)
|
|
112
|
-
assert_equal contents_test_json, result
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it "reads a zip file from within a gz file" do
|
|
116
|
-
result = IOStreams.reader(zip_gz_file_name, &:read)
|
|
117
|
-
assert_equal contents_test_txt, result
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
end
|
data/test/encode_reader_test.rb
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
require_relative "test_helper"
|
|
2
|
-
|
|
3
|
-
class EncodeReaderTest < Minitest::Test
|
|
4
|
-
describe IOStreams::Encode::Reader do
|
|
5
|
-
let :bad_data do
|
|
6
|
-
[
|
|
7
|
-
"New M\xE9xico,NE".b,
|
|
8
|
-
"good line",
|
|
9
|
-
"New M\xE9xico,\x07SF".b
|
|
10
|
-
].join("\n").encode("BINARY")
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
let :cleansed_data do
|
|
14
|
-
bad_data.gsub("\xE9".b, "")
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let :stripped_data do
|
|
18
|
-
cleansed_data.gsub("\x07", "")
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe "#read" do
|
|
22
|
-
describe "replacement" do
|
|
23
|
-
it "does not strip invalid characters" do
|
|
24
|
-
skip "Does not raise on JRuby" if defined?(JRuby)
|
|
25
|
-
input = StringIO.new(bad_data)
|
|
26
|
-
IOStreams::Encode::Reader.stream(input, encoding: "UTF-8") do |io|
|
|
27
|
-
assert_raises ::Encoding::UndefinedConversionError do
|
|
28
|
-
io.read.encoding
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "strips invalid characters" do
|
|
34
|
-
input = StringIO.new(bad_data)
|
|
35
|
-
data =
|
|
36
|
-
IOStreams::Encode::Reader.stream(input, encoding: "UTF-8", replace: "", &:read)
|
|
37
|
-
assert_equal cleansed_data, data
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
describe "printable" do
|
|
42
|
-
it "strips non-printable characters" do
|
|
43
|
-
input = StringIO.new(bad_data)
|
|
44
|
-
data =
|
|
45
|
-
IOStreams::Encode::Reader.stream(input, encoding: "UTF-8", cleaner: :printable, replace: "", &:read)
|
|
46
|
-
assert_equal stripped_data, data
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
data/test/encode_writer_test.rb
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
require_relative "test_helper"
|
|
2
|
-
|
|
3
|
-
class EncodeWriterTest < Minitest::Test
|
|
4
|
-
describe IOStreams::Encode::Writer do
|
|
5
|
-
let :bad_data do
|
|
6
|
-
[
|
|
7
|
-
"New M\xE9xico,NE".b,
|
|
8
|
-
"good line",
|
|
9
|
-
"New M\xE9xico,\x07SF".b
|
|
10
|
-
].join("\n").encode("BINARY")
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
let :cleansed_data do
|
|
14
|
-
bad_data.gsub("\xE9".b, "?")
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let :stripped_data do
|
|
18
|
-
cleansed_data.gsub("\x07", "")
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe "#<<" do
|
|
22
|
-
it "file" do
|
|
23
|
-
temp_file = Tempfile.new("rocket_job")
|
|
24
|
-
file_name = temp_file.to_path
|
|
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
|
|
31
|
-
result = File.read(file_name, mode: "rb")
|
|
32
|
-
assert_equal bad_data, result
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it "stream" do
|
|
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
|
|
43
|
-
assert_equal "ASCII-8BIT", io.string.encoding.to_s
|
|
44
|
-
assert_equal bad_data, io.string
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "stream as utf-8" do
|
|
48
|
-
io = StringIO.new("")
|
|
49
|
-
assert_raises Encoding::UndefinedConversionError do
|
|
50
|
-
IOStreams::Encode::Writer.stream(io, encoding: "UTF-8") do |encoded|
|
|
51
|
-
encoded << bad_data
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it "stream as utf-8 with replacement" do
|
|
57
|
-
io = StringIO.new("")
|
|
58
|
-
IOStreams::Encode::Writer.stream(io, encoding: "UTF-8", replace: "?") do |encoded|
|
|
59
|
-
encoded << bad_data
|
|
60
|
-
end
|
|
61
|
-
assert_equal "UTF-8", io.string.encoding.to_s
|
|
62
|
-
assert_equal cleansed_data, io.string
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "stream as utf-8 with replacement and printable cleansing" do
|
|
66
|
-
io = StringIO.new("")
|
|
67
|
-
IOStreams::Encode::Writer.stream(io, encoding: "UTF-8", replace: "?", cleaner: :printable) do |encoded|
|
|
68
|
-
encoded << bad_data
|
|
69
|
-
end
|
|
70
|
-
assert_equal "UTF-8", io.string.encoding.to_s
|
|
71
|
-
assert_equal stripped_data, io.string
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
describe ".write" do
|
|
76
|
-
it "returns byte count" do
|
|
77
|
-
io_string = StringIO.new("".b)
|
|
78
|
-
count = 0
|
|
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
|
|
85
|
-
assert_equal bad_data, io_string.string
|
|
86
|
-
assert_equal bad_data.size, count
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
Binary file
|
data/test/files/spreadsheet.xlsx
DELETED
|
Binary file
|
data/test/files/test.csv
DELETED
data/test/files/test.json
DELETED
data/test/files/test.psv
DELETED
data/test/files/text file.txt
DELETED
data/test/files/text.txt
DELETED
data/test/files/text.txt.bz2
DELETED
|
Binary file
|
data/test/files/text.txt.gz
DELETED
|
Binary file
|
data/test/files/text.txt.gz.zip
DELETED
|
Binary file
|
data/test/files/text.zip
DELETED
|
Binary file
|
data/test/files/text.zip.gz
DELETED
|
Binary file
|