Created
March 5, 2013 22:26
-
-
Save whalec/5094913 to your computer and use it in GitHub Desktop.
Stream a file in line by line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This will stream the file in line by line, | |
# rather than DOM parsing the whole file into memory. | |
require 'csv' | |
CSV.foreach("foo.csv") do |line| | |
csv_line = CSV.parse(line) | |
# Do active record insertion with it | |
SomeARClass.new(csv_line).save! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment