lib/ganapati/client.rb in ganapati-0.0.5 vs lib/ganapati/client.rb in ganapati-0.0.6

- old
+ new

@@ -51,22 +51,22 @@ end } end def readlines(path, sep="\n") - lastbit = "" + buffer = "" + readchunks(path) { |chunk| - parts = chunk.split(sep) - if parts.length == 0 - yield lastbit if lastbit != "" - elsif parts.length == 1 - yield lastbit + parts.first - else - yield lastbit + parts.first - parts.slice(1, parts.length).each { |p| yield p } + buffer << chunk + + # partitions[1] will be empty if sep does not exist in the string + while partitions = buffer.partition(sep) and !partitions[1].empty? + yield partitions.first + buffer = partitions.last end - lastbit = "" } + + yield buffer if buffer.size > 0 end # for writing to a new file def create(path, &block) file_handle :create, path, &block