L
Leslie Viljoen
Hello!
Running this following code:
f = File.open(filename, 'w')
f.truncate(10)
f.close
leaves the file filled with 10 zero bytes. Its pretty unexpected,
since the documentation makes no mention of this
(http://ruby-doc.org/core/classes/File.html#M002539).
File.truncate(filename, 10)
works fine, leaving any pre-existing bytes intact. Looking at the
example I assume this has to do with the File#truncate method
expecting me to write some bytes and then truncate them.
Just putting this out there for the next confused person since Google
made no mention of this!
Running this following code:
f = File.open(filename, 'w')
f.truncate(10)
f.close
leaves the file filled with 10 zero bytes. Its pretty unexpected,
since the documentation makes no mention of this
(http://ruby-doc.org/core/classes/File.html#M002539).
File.truncate(filename, 10)
works fine, leaving any pre-existing bytes intact. Looking at the
example I assume this has to do with the File#truncate method
expecting me to write some bytes and then truncate them.
Just putting this out there for the next confused person since Google
made no mention of this!