# position to append from
pos = content_range[/\d+/].to_i
f = File.open("#{filename}", "a") #f.pos = pos
f.seek(pos)
f.write(data)
f.close
I've tried opening the file with a and a+ modes. I've tried doing
rewing, setting pos (like the commented line) and seek, and none of them
works, the new data is always appended at the end of the file.
# position to append from
pos = content_range[/\d+/].to_i
f = File.open("#{filename}", "a") #f.pos = pos
f.seek(pos)
f.write(data)
f.close
I've tried opening the file with a and a+ modes. I've tried doing
rewing, setting pos (like the commented line) and seek, and none of them
works, the new data is always appended at the end of the file.
Open the file in r+ mode. This is read-write mode that starts at the beginning of the file and allows you to seek to a specific position.
If you want this to be cross-platform, make sure you actually open it
"rb+" or your code will mysteriously fail on Windows.
-austin
···
On 11/27/06, Tulsi Das <tulsidas@gmail.com> wrote:
Jamey Cribbs wrote:
> Open the file in r+ mode. This is read-write mode that starts at the
> beginning of the file and allows you to seek to a specific position.
I can't believe it was so easy, I've never even read the "r" section,
assuming it was read only... thanks a lot, it works great!