Heesob Park | 16 May 09:49

Re: Create an empty file of certain size

Robert Klemme wrote:
> 2008/5/16 Mark Dodwell <seo <at> mkdynamic.co.uk>:
>>> fd.truncate( 2 ** 20 )
>>
>> Thanks that's great, didn't know about that method!
> 
> If it does not work on your platform, you can speed up your solution
> by writing larger chunks:
> 
> BUFFER = ("a" * 1024).freeze
> File.open("tmp.txt", 'wb') { |f| 10.kilobytes.times { f.write BUFFER } }
> 
Here is another way:

size = 2**30
File.open("tmp.txt","wb"){|f|f.seek(size-1);f.write("\0")}

Regards,

Park Heesob
--

-- 
Posted via http://www.ruby-forum.com/.


Gmane