iostreams 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/Rakefile +7 -7
  4. data/lib/io_streams/builder.rb +4 -3
  5. data/lib/io_streams/bzip2/reader.rb +1 -1
  6. data/lib/io_streams/bzip2/writer.rb +1 -1
  7. data/lib/io_streams/deprecated.rb +2 -3
  8. data/lib/io_streams/encode/reader.rb +5 -8
  9. data/lib/io_streams/encode/writer.rb +1 -1
  10. data/lib/io_streams/io_streams.rb +5 -2
  11. data/lib/io_streams/line/reader.rb +2 -1
  12. data/lib/io_streams/path.rb +4 -4
  13. data/lib/io_streams/paths/http.rb +8 -10
  14. data/lib/io_streams/paths/matcher.rb +10 -11
  15. data/lib/io_streams/paths/s3.rb +6 -6
  16. data/lib/io_streams/paths/sftp.rb +38 -23
  17. data/lib/io_streams/pgp.rb +45 -35
  18. data/lib/io_streams/pgp/reader.rb +4 -6
  19. data/lib/io_streams/pgp/writer.rb +1 -2
  20. data/lib/io_streams/reader.rb +2 -2
  21. data/lib/io_streams/record/writer.rb +2 -4
  22. data/lib/io_streams/row/writer.rb +3 -5
  23. data/lib/io_streams/stream.rb +6 -6
  24. data/lib/io_streams/symmetric_encryption/reader.rb +1 -3
  25. data/lib/io_streams/symmetric_encryption/writer.rb +2 -6
  26. data/lib/io_streams/tabular.rb +12 -10
  27. data/lib/io_streams/tabular/header.rb +4 -4
  28. data/lib/io_streams/tabular/parser/array.rb +2 -4
  29. data/lib/io_streams/tabular/parser/csv.rb +3 -5
  30. data/lib/io_streams/tabular/parser/fixed.rb +4 -3
  31. data/lib/io_streams/tabular/parser/hash.rb +2 -4
  32. data/lib/io_streams/tabular/parser/json.rb +2 -4
  33. data/lib/io_streams/tabular/parser/psv.rb +5 -7
  34. data/lib/io_streams/tabular/utility/csv_row.rb +9 -17
  35. data/lib/io_streams/utils.rb +3 -3
  36. data/lib/io_streams/utils/reliable_http.rb +98 -0
  37. data/lib/io_streams/version.rb +1 -1
  38. data/lib/io_streams/writer.rb +1 -1
  39. data/lib/io_streams/xlsx/reader.rb +5 -5
  40. data/lib/io_streams/zip/reader.rb +1 -1
  41. data/lib/io_streams/zip/writer.rb +2 -2
  42. data/lib/iostreams.rb +34 -34
  43. data/test/builder_test.rb +74 -74
  44. data/test/bzip2_reader_test.rb +8 -13
  45. data/test/bzip2_writer_test.rb +8 -9
  46. data/test/deprecated_test.rb +25 -29
  47. data/test/encode_reader_test.rb +14 -18
  48. data/test/encode_writer_test.rb +29 -30
  49. data/test/gzip_reader_test.rb +8 -13
  50. data/test/gzip_writer_test.rb +10 -11
  51. data/test/io_streams_test.rb +35 -35
  52. data/test/line_reader_test.rb +35 -39
  53. data/test/line_writer_test.rb +8 -9
  54. data/test/minimal_file_reader.rb +1 -1
  55. data/test/path_test.rb +24 -24
  56. data/test/paths/file_test.rb +42 -42
  57. data/test/paths/http_test.rb +5 -5
  58. data/test/paths/matcher_test.rb +11 -12
  59. data/test/paths/s3_test.rb +44 -46
  60. data/test/paths/sftp_test.rb +18 -18
  61. data/test/pgp_reader_test.rb +13 -15
  62. data/test/pgp_test.rb +43 -44
  63. data/test/pgp_writer_test.rb +27 -28
  64. data/test/record_reader_test.rb +9 -10
  65. data/test/record_writer_test.rb +10 -11
  66. data/test/row_reader_test.rb +5 -6
  67. data/test/row_writer_test.rb +7 -8
  68. data/test/stream_test.rb +60 -62
  69. data/test/tabular_test.rb +111 -111
  70. data/test/test_helper.rb +22 -22
  71. data/test/utils_test.rb +7 -7
  72. data/test/xlsx_reader_test.rb +12 -12
  73. data/test/zip_reader_test.rb +14 -21
  74. data/test/zip_writer_test.rb +10 -10
  75. metadata +4 -3
@@ -1,52 +1,48 @@
1
- require_relative 'test_helper'
1
+ require_relative "test_helper"
2
2
 
3
3
  class EncodeReaderTest < Minitest::Test
4
4
  describe IOStreams::Encode::Reader do
5
5
  let :bad_data do
6
6
  [
7
7
  "New M\xE9xico,NE".b,
8
- 'good line',
8
+ "good line",
9
9
  "New M\xE9xico,\x07SF".b
10
- ].join("\n").encode('BINARY')
10
+ ].join("\n").encode("BINARY")
11
11
  end
12
12
 
13
13
  let :cleansed_data do
14
- bad_data.gsub("\xE9".b, '')
14
+ bad_data.gsub("\xE9".b, "")
15
15
  end
16
16
 
17
17
  let :stripped_data do
18
- cleansed_data.gsub("\x07", '')
18
+ cleansed_data.gsub("\x07", "")
19
19
  end
20
20
 
21
- describe '#read' do
22
- describe 'replacement' do
23
- it 'does not strip invalid characters' do
21
+ describe "#read" do
22
+ describe "replacement" do
23
+ it "does not strip invalid characters" do
24
24
  skip "Does not raise on JRuby" if defined?(JRuby)
25
25
  input = StringIO.new(bad_data)
26
- IOStreams::Encode::Reader.stream(input, encoding: 'UTF-8') do |io|
26
+ IOStreams::Encode::Reader.stream(input, encoding: "UTF-8") do |io|
27
27
  assert_raises ::Encoding::UndefinedConversionError do
28
28
  io.read.encoding
29
29
  end
30
30
  end
31
31
  end
32
32
 
33
- it 'strips invalid characters' do
33
+ it "strips invalid characters" do
34
34
  input = StringIO.new(bad_data)
35
35
  data =
36
- IOStreams::Encode::Reader.stream(input, encoding: 'UTF-8', replace: '') do |io|
37
- io.read
38
- end
36
+ IOStreams::Encode::Reader.stream(input, encoding: "UTF-8", replace: "", &:read)
39
37
  assert_equal cleansed_data, data
40
38
  end
41
39
  end
42
40
 
43
- describe 'printable' do
44
- it 'strips non-printable characters' do
41
+ describe "printable" do
42
+ it "strips non-printable characters" do
45
43
  input = StringIO.new(bad_data)
46
44
  data =
47
- IOStreams::Encode::Reader.stream(input, encoding: 'UTF-8', cleaner: :printable, replace: '') do |io|
48
- io.read
49
- end
45
+ IOStreams::Encode::Reader.stream(input, encoding: "UTF-8", cleaner: :printable, replace: "", &:read)
50
46
  assert_equal stripped_data, data
51
47
  end
52
48
  end
@@ -1,82 +1,81 @@
1
- require_relative 'test_helper'
1
+ require_relative "test_helper"
2
2
 
3
3
  class EncodeWriterTest < Minitest::Test
4
4
  describe IOStreams::Encode::Writer do
5
5
  let :bad_data do
6
6
  [
7
7
  "New M\xE9xico,NE".b,
8
- 'good line',
8
+ "good line",
9
9
  "New M\xE9xico,\x07SF".b
10
- ].join("\n").encode('BINARY')
10
+ ].join("\n").encode("BINARY")
11
11
  end
12
12
 
13
13
  let :cleansed_data do
14
- bad_data.gsub("\xE9".b, '?')
14
+ bad_data.gsub("\xE9".b, "?")
15
15
  end
16
16
 
17
17
  let :stripped_data do
18
- cleansed_data.gsub("\x07", '')
18
+ cleansed_data.gsub("\x07", "")
19
19
  end
20
20
 
21
- describe '#<<' do
22
- it 'file' do
23
- temp_file = Tempfile.new('rocket_job')
21
+ describe "#<<" do
22
+ it "file" do
23
+ temp_file = Tempfile.new("rocket_job")
24
24
  file_name = temp_file.to_path
25
- IOStreams::Encode::Writer.file(file_name, encoding: 'ASCII-8BIT') do |io|
25
+ IOStreams::Encode::Writer.file(file_name, encoding: "ASCII-8BIT") do |io|
26
26
  io << bad_data
27
27
  end
28
- result = File.read(file_name, mode: 'rb')
28
+ result = File.read(file_name, mode: "rb")
29
29
  assert_equal bad_data, result
30
30
  end
31
31
 
32
- it 'stream' do
33
- io = StringIO.new(''.b)
34
- IOStreams::Encode::Writer.stream(io, encoding: 'ASCII-8BIT') do |encoded|
32
+ it "stream" do
33
+ io = StringIO.new("".b)
34
+ IOStreams::Encode::Writer.stream(io, encoding: "ASCII-8BIT") do |encoded|
35
35
  encoded << bad_data
36
36
  end
37
- assert_equal 'ASCII-8BIT', io.string.encoding.to_s
37
+ assert_equal "ASCII-8BIT", io.string.encoding.to_s
38
38
  assert_equal bad_data, io.string
39
39
  end
40
40
 
41
- it 'stream as utf-8' do
42
- io = StringIO.new('')
41
+ it "stream as utf-8" do
42
+ io = StringIO.new("")
43
43
  assert_raises Encoding::UndefinedConversionError do
44
- IOStreams::Encode::Writer.stream(io, encoding: 'UTF-8') do |encoded|
44
+ IOStreams::Encode::Writer.stream(io, encoding: "UTF-8") do |encoded|
45
45
  encoded << bad_data
46
46
  end
47
47
  end
48
48
  end
49
49
 
50
- it 'stream as utf-8 with replacement' do
51
- io = StringIO.new('')
52
- IOStreams::Encode::Writer.stream(io, encoding: 'UTF-8', replace: '?') do |encoded|
50
+ it "stream as utf-8 with replacement" do
51
+ io = StringIO.new("")
52
+ IOStreams::Encode::Writer.stream(io, encoding: "UTF-8", replace: "?") do |encoded|
53
53
  encoded << bad_data
54
54
  end
55
- assert_equal 'UTF-8', io.string.encoding.to_s
55
+ assert_equal "UTF-8", io.string.encoding.to_s
56
56
  assert_equal cleansed_data, io.string
57
57
  end
58
58
 
59
- it 'stream as utf-8 with replacement and printable cleansing' do
60
- io = StringIO.new('')
61
- IOStreams::Encode::Writer.stream(io, encoding: 'UTF-8', replace: '?', cleaner: :printable) do |encoded|
59
+ it "stream as utf-8 with replacement and printable cleansing" do
60
+ io = StringIO.new("")
61
+ IOStreams::Encode::Writer.stream(io, encoding: "UTF-8", replace: "?", cleaner: :printable) do |encoded|
62
62
  encoded << bad_data
63
63
  end
64
- assert_equal 'UTF-8', io.string.encoding.to_s
64
+ assert_equal "UTF-8", io.string.encoding.to_s
65
65
  assert_equal stripped_data, io.string
66
66
  end
67
67
  end
68
68
 
69
- describe '.write' do
70
- it 'returns byte count' do
71
- io_string = StringIO.new(''.b)
69
+ describe ".write" do
70
+ it "returns byte count" do
71
+ io_string = StringIO.new("".b)
72
72
  count = 0
73
- IOStreams::Encode::Writer.stream(io_string, encoding: 'ASCII-8BIT') do |io|
73
+ IOStreams::Encode::Writer.stream(io_string, encoding: "ASCII-8BIT") do |io|
74
74
  count += io.write(bad_data)
75
75
  end
76
76
  assert_equal bad_data, io_string.string
77
77
  assert_equal bad_data.size, count
78
78
  end
79
79
  end
80
-
81
80
  end
82
81
  end
@@ -1,32 +1,27 @@
1
- require_relative 'test_helper'
1
+ require_relative "test_helper"
2
2
 
3
3
  class GzipReaderTest < Minitest::Test
4
4
  describe IOStreams::Gzip::Reader do
5
5
  let :file_name do
6
- File.join(File.dirname(__FILE__), 'files', 'text.txt.gz')
6
+ File.join(File.dirname(__FILE__), "files", "text.txt.gz")
7
7
  end
8
8
 
9
9
  let :decompressed do
10
- Zlib::GzipReader.open(file_name) { |gz| gz.read }
10
+ Zlib::GzipReader.open(file_name, &:read)
11
11
  end
12
12
 
13
- describe '.open' do
14
- it 'file' do
15
- result = IOStreams::Gzip::Reader.file(file_name) do |io|
16
- io.read
17
- end
13
+ describe ".open" do
14
+ it "file" do
15
+ result = IOStreams::Gzip::Reader.file(file_name, &:read)
18
16
  assert_equal decompressed, result
19
17
  end
20
18
 
21
- it 'stream' do
19
+ it "stream" do
22
20
  result = File.open(file_name) do |file|
23
- IOStreams::Gzip::Reader.stream(file) do |io|
24
- io.read
25
- end
21
+ IOStreams::Gzip::Reader.stream(file, &:read)
26
22
  end
27
23
  assert_equal decompressed, result
28
24
  end
29
25
  end
30
-
31
26
  end
32
27
  end
@@ -1,9 +1,9 @@
1
- require_relative 'test_helper'
1
+ require_relative "test_helper"
2
2
 
3
3
  class GzipWriterTest < Minitest::Test
4
4
  describe IOStreams::Gzip::Writer do
5
5
  let :temp_file do
6
- Tempfile.new('iostreams')
6
+ Tempfile.new("iostreams")
7
7
  end
8
8
 
9
9
  let :file_name do
@@ -11,35 +11,34 @@ class GzipWriterTest < Minitest::Test
11
11
  end
12
12
 
13
13
  let :decompressed do
14
- File.read(File.join(File.dirname(__FILE__), 'files', 'text.txt'))
14
+ File.read(File.join(File.dirname(__FILE__), "files", "text.txt"))
15
15
  end
16
16
 
17
17
  after do
18
18
  temp_file.delete
19
19
  end
20
20
 
21
- describe '.file' do
22
- it 'file' do
21
+ describe ".file" do
22
+ it "file" do
23
23
  IOStreams::Gzip::Writer.file(file_name) do |io|
24
24
  io.write(decompressed)
25
25
  end
26
- result = Zlib::GzipReader.open(file_name) { |gz| gz.read }
26
+ result = Zlib::GzipReader.open(file_name, &:read)
27
27
  temp_file.delete
28
28
  assert_equal decompressed, result
29
29
  end
30
30
 
31
- it 'stream' do
32
- io_string = StringIO.new(''.b)
31
+ it "stream" do
32
+ io_string = StringIO.new("".b)
33
33
  IOStreams::Gzip::Writer.stream(io_string) do |io|
34
34
  io.write(decompressed)
35
35
  end
36
- io = StringIO.new(io_string.string)
37
- gz = Zlib::GzipReader.new(io)
36
+ io = StringIO.new(io_string.string)
37
+ gz = Zlib::GzipReader.new(io)
38
38
  data = gz.read
39
39
  gz.close
40
40
  assert_equal decompressed, data
41
41
  end
42
42
  end
43
-
44
43
  end
45
44
  end
@@ -1,78 +1,78 @@
1
- require_relative 'test_helper'
1
+ require_relative "test_helper"
2
2
 
3
3
  module IOStreams
4
4
  class PathTest < Minitest::Test
5
5
  describe IOStreams do
6
- describe '.root' do
7
- it 'return default path' do
8
- path = ::File.expand_path(::File.join(__dir__, '../tmp/default'))
6
+ describe ".root" do
7
+ it "return default path" do
8
+ path = ::File.expand_path(::File.join(__dir__, "../tmp/default"))
9
9
  assert_equal path, IOStreams.root.to_s
10
10
  end
11
11
 
12
- it 'return downloads path' do
13
- path = ::File.expand_path(::File.join(__dir__, '../tmp/downloads'))
12
+ it "return downloads path" do
13
+ path = ::File.expand_path(::File.join(__dir__, "../tmp/downloads"))
14
14
  assert_equal path, IOStreams.root(:downloads).to_s
15
15
  end
16
16
  end
17
17
 
18
- describe '.join' do
19
- it 'returns path' do
18
+ describe ".join" do
19
+ it "returns path" do
20
20
  assert_equal IOStreams.root.to_s, IOStreams.join.to_s
21
21
  end
22
22
 
23
- it 'adds path to root' do
24
- assert_equal ::File.join(IOStreams.root.to_s, 'test'), IOStreams.join('test').to_s
23
+ it "adds path to root" do
24
+ assert_equal ::File.join(IOStreams.root.to_s, "test"), IOStreams.join("test").to_s
25
25
  end
26
26
 
27
- it 'adds paths to root' do
28
- assert_equal ::File.join(IOStreams.root.to_s, 'test', 'second', 'third'), IOStreams.join('test', 'second', 'third').to_s
27
+ it "adds paths to root" do
28
+ assert_equal ::File.join(IOStreams.root.to_s, "test", "second", "third"), IOStreams.join("test", "second", "third").to_s
29
29
  end
30
30
 
31
- it 'returns path and filename' do
32
- path = ::File.join(IOStreams.root.to_s, 'file.xls')
33
- assert_equal path, IOStreams.join('file.xls').to_s
31
+ it "returns path and filename" do
32
+ path = ::File.join(IOStreams.root.to_s, "file.xls")
33
+ assert_equal path, IOStreams.join("file.xls").to_s
34
34
  end
35
35
 
36
- it 'adds path to root and filename' do
37
- path = ::File.join(IOStreams.root.to_s, 'test', 'file.xls')
38
- assert_equal path, IOStreams.join('test', 'file.xls').to_s
36
+ it "adds path to root and filename" do
37
+ path = ::File.join(IOStreams.root.to_s, "test", "file.xls")
38
+ assert_equal path, IOStreams.join("test", "file.xls").to_s
39
39
  end
40
40
 
41
- it 'adds paths to root' do
42
- path = ::File.join(IOStreams.root.to_s, 'test', 'second', 'third', 'file.xls')
43
- assert_equal path, IOStreams.join('test', 'second', 'third', 'file.xls').to_s
41
+ it "adds paths to root" do
42
+ path = ::File.join(IOStreams.root.to_s, "test", "second", "third", "file.xls")
43
+ assert_equal path, IOStreams.join("test", "second", "third", "file.xls").to_s
44
44
  end
45
45
 
46
- it 'return path as sent in when full path' do
47
- path = ::File.join(IOStreams.root.to_s, 'file.xls')
46
+ it "return path as sent in when full path" do
47
+ path = ::File.join(IOStreams.root.to_s, "file.xls")
48
48
  assert_equal path, IOStreams.join(path).to_s
49
49
  end
50
50
  end
51
51
 
52
- describe '.path' do
53
- it 'default' do
54
- path = IOStreams.path('a.xyz')
52
+ describe ".path" do
53
+ it "default" do
54
+ path = IOStreams.path("a.xyz")
55
55
  assert path.is_a?(IOStreams::Paths::File), path
56
56
  end
57
57
 
58
- it 's3' do
59
- skip 'TODO'
60
- IOStreams.path('s3://a.xyz')
58
+ it "s3" do
59
+ skip "TODO"
60
+ IOStreams.path("s3://a.xyz")
61
61
  assert_equal :s3, path
62
62
  end
63
63
  end
64
64
 
65
- describe '.temp_file' do
66
- it 'returns value from block' do
67
- result = IOStreams.temp_file('base', '.ext') { |_path| 257 }
65
+ describe ".temp_file" do
66
+ it "returns value from block" do
67
+ result = IOStreams.temp_file("base", ".ext") { |_path| 257 }
68
68
  assert_equal 257, result
69
69
  end
70
70
 
71
- it 'supplies new temp file_name' do
71
+ it "supplies new temp file_name" do
72
72
  path1 = nil
73
73
  path2 = nil
74
- IOStreams.temp_file('base', '.ext') { |path| path1 = path }
75
- IOStreams.temp_file('base', '.ext') { |path| path2 = path }
74
+ IOStreams.temp_file("base", ".ext") { |path| path1 = path }
75
+ IOStreams.temp_file("base", ".ext") { |path| path2 = path }
76
76
  refute_equal path1.to_s, path2.to_s
77
77
  assert path1.is_a?(IOStreams::Paths::File), path1
78
78
  assert path2.is_a?(IOStreams::Paths::File), path2
@@ -1,25 +1,23 @@
1
- require_relative 'test_helper'
1
+ require_relative "test_helper"
2
2
 
3
3
  class LineReaderTest < Minitest::Test
4
4
  describe IOStreams::Line::Reader do
5
5
  let :file_name do
6
- File.join(File.dirname(__FILE__), 'files', 'text.txt')
6
+ File.join(File.dirname(__FILE__), "files", "text.txt")
7
7
  end
8
8
 
9
9
  let :csv_file do
10
- File.join(File.dirname(__FILE__), 'files', 'embedded_lines_test.csv')
10
+ File.join(File.dirname(__FILE__), "files", "embedded_lines_test.csv")
11
11
  end
12
12
 
13
13
  let :unclosed_quote_file do
14
- File.join(File.dirname(__FILE__), 'files', 'unclosed_quote_test.csv')
14
+ File.join(File.dirname(__FILE__), "files", "unclosed_quote_test.csv")
15
15
  end
16
16
 
17
17
  let :data do
18
18
  data = []
19
- File.open(file_name, 'rt') do |file|
20
- while !file.eof?
21
- data << file.readline.strip
22
- end
19
+ File.open(file_name, "rt") do |file|
20
+ data << file.readline.strip until file.eof?
23
21
  end
24
22
  data
25
23
  end
@@ -31,10 +29,9 @@ class LineReaderTest < Minitest::Test
31
29
  # "John","Firstname\n is John","234568"
32
30
  # "Zack","Firstname is Zack","234568\n"
33
31
  #
34
- describe 'embedded_within_quotes' do
35
- describe 'csv file' do
36
-
37
- it 'fails to keep embedded lines if flag is not set' do
32
+ describe "embedded_within_quotes" do
33
+ describe "csv file" do
34
+ it "fails to keep embedded lines if flag is not set" do
38
35
  lines = []
39
36
  IOStreams::Line::Reader.file(csv_file) do |io|
40
37
  io.each do |line|
@@ -44,7 +41,7 @@ class LineReaderTest < Minitest::Test
44
41
  assert_equal 7, lines.count
45
42
  end
46
43
 
47
- it 'keeps embedded lines if flag is set' do
44
+ it "keeps embedded lines if flag is set" do
48
45
  lines = []
49
46
  IOStreams::Line::Reader.file(csv_file, embedded_within: '"') do |io|
50
47
  io.each do |line|
@@ -54,7 +51,7 @@ class LineReaderTest < Minitest::Test
54
51
  assert_equal 4, lines.count
55
52
  end
56
53
 
57
- it 'raises error for unclosed quote' do
54
+ it "raises error for unclosed quote" do
58
55
  assert_raises(RuntimeError) do
59
56
  IOStreams::Line::Reader.file(unclosed_quote_file, embedded_within: '"') do |io|
60
57
  io.each do |line|
@@ -65,8 +62,8 @@ class LineReaderTest < Minitest::Test
65
62
  end
66
63
  end
67
64
 
68
- describe '#each' do
69
- it 'each_line file' do
65
+ describe "#each" do
66
+ it "each_line file" do
70
67
  lines = []
71
68
  count = IOStreams::Line::Reader.file(file_name) do |io|
72
69
  io.each { |line| lines << line }
@@ -75,7 +72,7 @@ class LineReaderTest < Minitest::Test
75
72
  assert_equal data.size, count
76
73
  end
77
74
 
78
- it 'each_line stream' do
75
+ it "each_line stream" do
79
76
  lines = []
80
77
  count = File.open(file_name) do |file|
81
78
  IOStreams::Line::Reader.stream(file) do |io|
@@ -108,7 +105,7 @@ class LineReaderTest < Minitest::Test
108
105
  end
109
106
  end
110
107
 
111
- ['@', 'BLAH'].each do |delimiter|
108
+ ["@", "BLAH"].each do |delimiter|
112
109
  it "reads delimited #{delimiter.inspect}" do
113
110
  lines = []
114
111
  stream = StringIO.new(data.join(delimiter))
@@ -120,10 +117,10 @@ class LineReaderTest < Minitest::Test
120
117
  end
121
118
  end
122
119
 
123
- it 'reads binary delimited' do
120
+ it "reads binary delimited" do
124
121
  delimiter = "\x01"
125
122
  lines = []
126
- stream = StringIO.new(data.join(delimiter).encode('ASCII-8BIT'))
123
+ stream = StringIO.new(data.join(delimiter).encode("ASCII-8BIT"))
127
124
  count = IOStreams::Line::Reader.stream(stream, buffer_size: 15, delimiter: delimiter) do |io|
128
125
  io.each { |line| lines << line }
129
126
  end
@@ -131,12 +128,12 @@ class LineReaderTest < Minitest::Test
131
128
  assert_equal data.size, count
132
129
  end
133
130
 
134
- describe '#readline' do
135
- let(:short_line) { '0123456789' }
136
- let(:longer_line) { 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' }
131
+ describe "#readline" do
132
+ let(:short_line) { "0123456789" }
133
+ let(:longer_line) { "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }
137
134
  let(:delimiter) { "\r\n" }
138
135
 
139
- it 'reads delimiter in first block, no delimiter at end' do
136
+ it "reads delimiter in first block, no delimiter at end" do
140
137
  data = [short_line, longer_line].join(delimiter)
141
138
  buffer_size = short_line.length + delimiter.size + (longer_line.size / 2)
142
139
 
@@ -153,7 +150,7 @@ class LineReaderTest < Minitest::Test
153
150
  end
154
151
  end
155
152
 
156
- it 'reads delimiter in second block, no delimiter at end' do
153
+ it "reads delimiter in second block, no delimiter at end" do
157
154
  data = [longer_line, short_line, short_line].join(delimiter)
158
155
  buffer_size = (longer_line.length + delimiter.size + 5) / 2
159
156
 
@@ -169,7 +166,7 @@ class LineReaderTest < Minitest::Test
169
166
  end
170
167
  end
171
168
 
172
- it 'reads delimiter split across first and second blocks' do
169
+ it "reads delimiter split across first and second blocks" do
173
170
  data = [longer_line, short_line, short_line].join(delimiter)
174
171
  buffer_size = longer_line.length + 1
175
172
 
@@ -185,8 +182,8 @@ class LineReaderTest < Minitest::Test
185
182
  end
186
183
  end
187
184
 
188
- it 'reads file with no matching delimiter' do
189
- delimiter = '@'
185
+ it "reads file with no matching delimiter" do
186
+ delimiter = "@"
190
187
  data = [longer_line, short_line, longer_line].join(delimiter) + delimiter
191
188
  buffer_size = longer_line.length + 1
192
189
 
@@ -200,7 +197,7 @@ class LineReaderTest < Minitest::Test
200
197
  end
201
198
  end
202
199
 
203
- it 'reads small file with no matching delimiter' do
200
+ it "reads small file with no matching delimiter" do
204
201
  data = short_line
205
202
  buffer_size = short_line.length + 100
206
203
 
@@ -214,8 +211,8 @@ class LineReaderTest < Minitest::Test
214
211
  end
215
212
  end
216
213
 
217
- it 'reads last line with the delimiter as the last character' do
218
- delimiter = '@'
214
+ it "reads last line with the delimiter as the last character" do
215
+ delimiter = "@"
219
216
  data = [longer_line, short_line, longer_line].join(delimiter) + delimiter
220
217
  buffer_size = longer_line.length + 1
221
218
 
@@ -231,7 +228,7 @@ class LineReaderTest < Minitest::Test
231
228
  end
232
229
  end
233
230
 
234
- it 'reads last line with the multi-byte delimiter as the last bytes' do
231
+ it "reads last line with the multi-byte delimiter as the last bytes" do
235
232
  data = [longer_line, short_line, longer_line].join(delimiter) + delimiter
236
233
  buffer_size = longer_line.length + 1
237
234
 
@@ -247,10 +244,10 @@ class LineReaderTest < Minitest::Test
247
244
  end
248
245
  end
249
246
 
250
- describe 'read 1 char at a time' do
247
+ describe "read 1 char at a time" do
251
248
  let(:buffer_size) { 1 }
252
249
 
253
- it 'delimiter at the end' do
250
+ it "delimiter at the end" do
254
251
  data = [longer_line, short_line, longer_line].join(delimiter) + delimiter
255
252
 
256
253
  stream = StringIO.new(data)
@@ -265,7 +262,7 @@ class LineReaderTest < Minitest::Test
265
262
  end
266
263
  end
267
264
 
268
- it 'no delimiter at the end' do
265
+ it "no delimiter at the end" do
269
266
  data = [longer_line, short_line, longer_line].join(delimiter)
270
267
 
271
268
  stream = StringIO.new(data)
@@ -281,21 +278,20 @@ class LineReaderTest < Minitest::Test
281
278
  end
282
279
  end
283
280
 
284
- it 'reads empty file' do
281
+ it "reads empty file" do
285
282
  stream = StringIO.new
286
283
  IOStreams::Line::Reader.stream(stream) do |io|
287
284
  assert io.eof?
288
285
  end
289
286
  end
290
287
 
291
- it 'prevents denial of service' do
292
- data = 'a' * IOStreams::Line::Reader::MAX_BLOCKS_MULTIPLIER + 'a'
288
+ it "prevents denial of service" do
289
+ data = "a" * IOStreams::Line::Reader::MAX_BLOCKS_MULTIPLIER + "a"
293
290
  stream = StringIO.new(data)
294
291
  assert_raises IOStreams::Errors::DelimiterNotFound do
295
292
  IOStreams::Line::Reader.stream(stream, buffer_size: 1) do |io|
296
293
  end
297
294
  end
298
-
299
295
  end
300
296
  end
301
297
  end