I want to iteratively read a fixed number of bytes in a file, and return them
My code is below. I have taken it from an example on the internet
File.open('textfile.txt') do |file|
while (buffer = file.read(size)) do
yield buffer
end
end
I get the error no block given.
Well, that’s because no block is given. You can either replace
yield bufferwithputs buffer(or any operation you want) or create a separate method taking code block:and call it like this
Add normal parameters (like file name or block size) to
read_file, if necessary.