ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
ruby File#sysread
by Aatch other posts by this author
Jun 14 2007 7:08PM messages near this date
Re: load "file-name" question | Re: ruby File#sysread
I am attempting to create a program that can transfer files. It so far
can send pure-text files no problem, but it has issues with reading
anything else. EG. It cut a 6 MB mp3 down to a 6 kb file.

After a bit of fiddling around I found that the program wasn't reading
the file properly. I'm currently using File#sysread to read the file and
File#syswrite to write the file. I don't know why it wont read the whole
file, can some body please help. Here is a copy of a similar program
with the same problem. (please dont mock it uselessness, it was made to
try and sort aforementioned problem).


f1 = File.new("BIG.txt")
f2 = File.new("big.txt", "w")

contents = f1.sysread(f1.stat.size-2)

print f1.stat.size.to_s + "\n"
print contents.length.to_s + "\n"

f2.syswrite contents

print f2.stat.size.to_s + "\n"

sleep 2

-- 
Posted via http://www.ruby-forum.com/.
Thread:
Aatch
Tim Hunter
Bill Kelly
Aatch Random
Nobuyoshi Nakada
James Milner

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved