Ruby increase file size on the fly for testing -
this may sound weird, or why want that.
i'm trying write cucumber feature test uploading large image file (>16m) so, don't want store large file on github or in project. i'm using imagemagick create image far can 1m. can increase file size in ruby? don't care content inside file, file size. thanks, there anyway trick cucumber believe me i'm uploading large file size?
thanks
the dd(1) tool can make file quite large while using little disk space:
$ dd if=/dev/zero of=huge bs=1024 count=1 seek=100000 1+0 records in 1+0 records out 1024 bytes (1.0 kb) copied, 4.9857e-05 s, 20.5 mb/s $ ls -lh huge -rw-r--r-- 1 sarnold sarnold 98m 2011-07-03 02:43 huge $ du -h huge 12k huge the file huge looks 102400000 bytes long. (roughly 98m.) takes 12 kilobytes on disk, because seek parameter dd(1) causes start writing way "into" file. if earlier bytes read, os supply endless stream of zeros. (0x00 kind of zeros, not ascii kind of zeros: "0".)
if wanted replicate in ruby, you'd use file#seek function:
irb> f=file.new("huge", "w+") => #<file:huge> irb> f.seek(100000 * 1024) => 0 irb> f.write("hello") => 5 irb> f.close() => nil irb> ^d $ ls -lh huge -rw-r--r-- 1 sarnold sarnold 98m 2011-07-03 02:47 huge $
Comments
Post a Comment