Forum: Ruby how do i detect END OF FILE file in ruby

4b1d69e2ac9037081497056f70196369?d=identicon&s=25 Amit Tomar (amit-singh)
on 2010-10-06 10:07
Hi all,
         i would like to know how do i detect END OF FILE file in
ruby.is there
any EOF operator  in ruby???
E088bb5c80fd3c4fd02c2020cdacbaf0?d=identicon&s=25 Jesús Gabriel y Galán (Guest)
on 2010-10-06 10:18
(Received via mailing list)
On Wed, Oct 6, 2010 at 10:07 AM, Amit Tomar <amittomer25@yahoo.com>
wrote:
> Hi all,
>         i would like to know how do i detect END OF FILE file in
> ruby.is there
> any EOF operator  in ruby???

Usually the ways of reading a file in Ruby are higher level, where the
EOF is handled for you:

content = File.read("file.txt")
content = File.readlines("file.txt")
File.foreach("file.txt") {|line| content << line}

and so on.

What are you trying to do?

Jesus.
4b1d69e2ac9037081497056f70196369?d=identicon&s=25 Amit Tomar (amit-singh)
on 2010-10-06 10:26
Jesús Gabriel y Galán wrote:
> On Wed, Oct 6, 2010 at 10:07 AM, Amit Tomar <amittomer25@yahoo.com>
> wrote:
>> Hi all,
>> ? ? ? ? i would like to know how do i detect END OF FILE file in
>> ruby.is there
>> any EOF operator ?in ruby???
>
> Usually the ways of reading a file in Ruby are higher level, where the
> EOF is handled for you:
>
> content = File.read("file.txt")
> content = File.readlines("file.txt")
> File.foreach("file.txt") {|line| content << line}
>
> and so on.
>
> What are you trying to do?
>
> Jesus.

             Am looking to configure mongrels's http_request.rb in
order to
delete mongrel temporary file after upload .This is what i would like to
have


def initialize(params, socket, dispatchers)
      @params = params
      @socket = socket
      @dispatchers = dispatchers
      content_length = @params[Const::CONTENT_LENGTH].to_i
      remain = content_length - @params.http_body.length

      # tell all dispatchers the request has begun
      @dispatchers.each do |dispatcher|
        dispatcher.request_begins(@params)
      end unless @dispatchers.nil? || @dispatchers.empty?

      # Some clients (like FF1.0) report 0 for body and then send a
body.  This will probably truncate them but at least the request goes
through usually.
      if remain <= 0
        # we've got everything, pack it up
        @body = StringIO.new
        @body.write @params.http_body
        update_request_progress(0, content_length)
      elsif remain > 0
        # must read more data to complete body
        if remain > Const::MAX_BODY
          # huge body, put it in a tempfile
          @body = Tempfile.new(Const::MONGREL_TMP_BASE)
          @body.binmode
        else
          # small body, just use that
          @body = StringIO.new
        end

        @body.write @params.http_body
        read_body(remain, content_length)
      end

      @body.rewind if @body
    end

Here i would like to close this @body after use by using something like
@body.close but while doing so am getting error what should i do and
whre should i call this @body.close
i am looking to close @body after eof reached
5b2b0852d464f20072e6c1961784a6c8?d=identicon&s=25 Rajinder Yadav (Guest)
on 2010-10-07 03:33
(Received via mailing list)
On 10-10-06 04:07 AM, Amit Tomar wrote:
> Hi all,
>           i would like to know how do i detect END OF FILE file in
> ruby.is there
> any EOF operator  in ruby???

you can use IO.eof?

http://www.ruby-doc.org/core/classes/IO.html#M002285
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.