From: niklas | brueckenschlaeger Date: 2010-11-17T07:07:40+09:00 Subject: Re: File#truncate fills file with zeros --=-K12NVC1TkvPt4sHBdr2s Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable this is because opening a file with "w" truncates it. On Wed, 2010-11-17 at 06:33 +0900, Leslie Viljoen wrote: > Hello! >=20 > Running this following code: >=20 > f =3D File.open(filename, 'w') > f.truncate(10) > f.close >=20 > 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). >=20 > File.truncate(filename, 10) >=20 > 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. >=20 > Just putting this out there for the next confused person since Google > made no mention of this! >=20 --=-K12NVC1TkvPt4sHBdr2s Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQIbBAABAgAGBQJM4wCOAAoJEIQdQGZOjo82KGoP+OhNQuvx/Mv1Txc2SMZ8z7Is o+DJE7hx8E+2RPTJhC5Gl8Nury8qSIMosXEzNosLAWZPOvDVypjq/ki2nkIpDaos L5RgmOfPE3jNDv3Co6g4c6d3a/izueUihGtl2ScqqqxIaMRyq/F+l52sT5RG1ew4 pCmW4aAxobRuT//g/iUjERZDDd1cdb5rm7CN7pT6FCu1ZP7BZ0FypqL4CgsipuZh LwaSMSmhNJcU8bGD6FQxKVmB0zyergFVt80I5CzhSxVw0IV69xu6wy3kxRU+bLf1 Jm8T6yoDrBhnLwDiZ79Ew5PRP6UlbzUmlDBelAnzNqsDc7GkktdScvgMCgAacqKD ZO7vu6KJWCn3OP8rEdmrQlTAZ/GV/bcOH7XrTYJYDZBB1c1yD0RGvMo1F5FtT1me FJYuAEdVmE4C7Z+ZBWImZj/kBzp12k+yB9mlXINswqjPWc5je4MyP5VpF19WbszE cR2dgG2kQX/rSB1Xk2clkI8PO9G5s1sV/Fn8TPCdP7rxgFRwLQBH4iV2nl6YGlO5 PelnG6uRuoAvUB/e9aQvF3bmlGzhffPbnf6vKfCcIKPp0Cxxhg2h5APUn+y3DGuk GZBEs6KQvOgEYZW3RMdkQSuWH2FLv34+6zYQ6g/o2Ww6nqL/8d+Suu2pyFsyr9lB 9GzCaud/gJmeEVQBOu4= =JA7o -----END PGP SIGNATURE----- --=-K12NVC1TkvPt4sHBdr2s--