Skip to content

Commit

Permalink
Using Less Memory And Quicker Line Counter (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michaelkeene authored Jul 26, 2023
1 parent 11b5e2f commit 6f8f1ec
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/csvbuilder/importer/internal/import/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def initialize(file_path)
reset
end

# http://stackoverflow.com/questions/2650517/count-the-number-of-lines-in-a-file-without-reading-entire-file-into-memory
# https://gist.github.com/guilhermesimoes/d69e547884e556c3dc95?permalink_comment_id=4502636#gistcomment-4502636
# @return [Integer] the number of rows in the file, including empty new lines
def size
@size ||= ::File.readlines(file_path).length
@size ||= ::File.read(file_path).count($/)
end

# If the current position is at the headers, skip it and return it. Otherwise, only return false.
Expand Down

0 comments on commit 6f8f1ec

Please sign in to comment.