Skip to content

Instantly share code, notes, and snippets.

@whalec
Created March 5, 2013 22:26
Show Gist options
  • Save whalec/5094913 to your computer and use it in GitHub Desktop.
Save whalec/5094913 to your computer and use it in GitHub Desktop.
Stream a file in line by line.
# 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