Class: RedshiftConnector::Reader::RedshiftCSV::ScanBuffer
- Inherits:
-
Object
- Object
- RedshiftConnector::Reader::RedshiftCSV::ScanBuffer
- Defined in:
- lib/redshift_connector/reader/redshift_csv.rb
Constant Summary collapse
- MAX_COLUMN_LENGTH =
1.2MB
(1.2 * (1024 ** 3)).to_i
Instance Method Summary collapse
- #eof? ⇒ Boolean
- #fill_buffer ⇒ Object
-
#initialize(f) ⇒ ScanBuffer
constructor
A new instance of ScanBuffer.
- #lineno ⇒ Object
- #next_row ⇒ Object
- #read_eol ⇒ Object
- #read_separator ⇒ Object
- #scan_column ⇒ Object
Constructor Details
#initialize(f) ⇒ ScanBuffer
Returns a new instance of ScanBuffer.
66 67 68 69 70 |
# File 'lib/redshift_connector/reader/redshift_csv.rb', line 66 def initialize(f) @f = f @s = StringScanner.new("") @eof = false end |
Instance Method Details
#eof? ⇒ Boolean
72 73 74 |
# File 'lib/redshift_connector/reader/redshift_csv.rb', line 72 def eof? @s.eos? && @eof end |
#fill_buffer ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/redshift_connector/reader/redshift_csv.rb', line 99 def fill_buffer line = @f.gets if line @s << line true else @eof = true false end end |
#lineno ⇒ Object
76 77 78 |
# File 'lib/redshift_connector/reader/redshift_csv.rb', line 76 def lineno @f.lineno end |
#next_row ⇒ Object
80 81 82 |
# File 'lib/redshift_connector/reader/redshift_csv.rb', line 80 def next_row fill_buffer end |
#read_eol ⇒ Object
114 115 116 |
# File 'lib/redshift_connector/reader/redshift_csv.rb', line 114 def read_eol @s.skip(/[ \t\r]*(?:\n|\z)/) end |
#read_separator ⇒ Object
110 111 112 |
# File 'lib/redshift_connector/reader/redshift_csv.rb', line 110 def read_separator @s.skip(/[ \t]*,/) end |
#scan_column ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/redshift_connector/reader/redshift_csv.rb', line 86 def scan_column s = @s s.skip(/[ \t]+/) until column = s.scan(/"(?:\\.|[^"\\])*"/m) fill_buffer or return nil return nil if s.eos? if s.rest_size > MAX_COLUMN_LENGTH raise Reader::MalformedCSVException, "CSV parse error: too long column at line #{@f.lineno}" end end column end |