I hand my "fake_file" off to some code to play with, but keep a reference for my testing purposes. At times, I need to clear the accumulated output, but as you can see truncate() is giving me fits.
Can anyone suggest how I might clear the StringIO object, without replacing it?
I hand my "fake_file" off to some code to play with, but keep a
reference for my testing purposes. At times, I need to clear the
accumulated output, but as you can see truncate() is giving me fits.
Can anyone suggest how I might clear the StringIO object, without
replacing it?
I think #truncate simply memset()s the buffer but it does not
change the position of the file pointer, so you would probably
need to #seek 0, as well.
Thanks.
James Edward Gray II
E
···
Le 26/4/2005, "James Edward Gray II" <james@grayproductions.net> a écrit:
I'm working with StringIO to write some test code and it is behaving
strangely. Check out this example:
irb(main):001:0> require "stringio"
=> true
irb(main):002:0> fake_file = StringIO.new
=> #<StringIO:0x3119cc>
irb(main):003:0> fake_file.puts "This is a test."
=> nil
irb(main):004:0> fake_file.string
=> "This is a test.\n"
irb(main):005:0> fake_file.truncate(0)
=> 0
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
although gold dust is precious, when it gets in your eyes, it obstructs
your vision. --hsi-tang
The truncate() function shall cause the regular file named by path to have a size which shall be equal to length bytes.
If the file previously was larger than length, the extra data is discarded. If the file was previously shorter than length, its size is increased, and the extended area appears as if it were zero-filled.