In a situation like so:
FasterCSV.parse(uploaded_file) do |row|
@rows[i] = row
i += 1
break row if i == 10
end
Does FasterCSV read the entire file, or just the first 10 rows? I want to display the first couple lines of a CSV file, but don’t want to store the entire file in memory. Is this possible?
You can use FasterCSV to parse a file a line-at-a-time.
From the FasterCSV documentation:
(Note: In your question, you are using FasterCSV.parse, which is only used to parse Strings into CSV. Because you want to use files, look at the .foreach and .parse methods, which will handle opening and scanning the file for you.).