[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Weird File Problem - A Detective Story

Chris Parker

1/15/2006 2:08:00 AM

Here is a very simple example of the problem:

irb(main):001:0> i = 0
=> 0
irb(main):002:0>
File.open("tcpdump/al2ak_contents.dat"){|file|file.each_byte{|byte|
i+=1};print i}
794=> nil
irb(main):003:0> File.size("tcpdump/al2ak_contents.dat")
=> 3329
irb(main):004:0>
File.open("tcpdump/al2ak_contents.dat"){|file|file.each_byte{|byte|
};file.eof?}
=> true

i should be equal to the size of the file. This is definitely a real
difference. The file actually has 3329 bytes in it. That is what the
OS thinks and something close to that is what opening the file shows.

irb(main):019:0>
File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|};file.pos}
=> 3329

This implies that some bytes are being ignored or that each_byte just
sets pos to file size at the end.

irb(main):028:0>
File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
i+=1};file.seek(i);file.read;}
=> "\r\016\f\021\017\022\023\024\023\022\017\030\030"
irb(main):029:0>
File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
i+=1};file.seek(i);file.read;file.eof}
=> true
irb(main):030:0>
File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
i+=1};file.seek(i);file.read;file.eof;file.pos}
=> 1306
irb(main):031:0>
File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
i+=1};file.seek(i);file.read.length}
=> 13

So we are at eof after reading i bytes, as shown above, but I seek to i
and then read another 13 bytes before eof again. But look at the huge
chance in pos, which didn't go to 3329 this time. Let's try going to
i+13

irb(main):021:0>
File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
i+=1};file.seek(i+13);file.read;}
=> ""
irb(main):022:0>
File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
i+=1};file.seek(i+13);file.read;file.eof;}
=> true
irb(main):023:0>
File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
i+=1};file.seek(i+13);file.read;file.eof;file.pos}
=> 1319

That sort of makes sense. If 1306 was actually the end of file, then
adding 13 to it would produce exactly these results. Adding 14 to i
has the same results as 13. Adding 15 to i has an different outcome:

irb(main):043:0>
File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
i+=1};file.seek(i+15);file.read}
=>
"\030\030#\"\"\"#''''''''''\001\t\010\010\t\n\t\v\t\t\v\016\v\r\v\016\021\016
\016\016\016\021\023\r\r\016\r\r\023\030\021\017\017\017\017\021\030\026\027\024
\024\024\027\026"
irb(main):044:0>
File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
i+=1};file.seek(i+15);file.read;file.eof}
=> true
irb(main):045:0>
File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
i+=1};file.seek(i+15);file.read;file.eof;file.pos}
=> 1321

So adding 15 to i returns a new string of bytes and gets an eof again
and doesn't move the pos past 1306 + 15.

I am at a loss for explaining what is going on here. Why can't
each_byte get to the true eof? And why can I seek to the true eof (I
didn't show it, but it worked) if each_byte can't make it there?

Any help is appreciated. I'll try to answer any questions as well.

Sincerely,

Chris Parker

29 Answers

William James

1/15/2006 10:18:00 AM

0


Chris Parker wrote:
> Here is a very simple example of the problem:
>
> irb(main):001:0> i = 0
> => 0
> irb(main):002:0>
> File.open("tcpdump/al2ak_contents.dat"){|file|file.each_byte{|byte|
> i+=1};print i}
> 794=> nil
> irb(main):003:0> File.size("tcpdump/al2ak_contents.dat")
> => 3329
> irb(main):004:0>
> File.open("tcpdump/al2ak_contents.dat"){|file|file.each_byte{|byte|
> };file.eof?}
> => true
>
> i should be equal to the size of the file. This is definitely a real
> difference. The file actually has 3329 bytes in it. That is what the
> OS thinks and something close to that is what opening the file shows.

Is this under windoze?

Robert Klemme

1/15/2006 12:45:00 PM

0

Chris Parker <chrisgparker@gmail.com> wrote:
> Here is a very simple example of the problem:
>
> irb(main):001:0> i = 0
> => 0
> irb(main):002:0>
> File.open("tcpdump/al2ak_contents.dat"){|file|file.each_byte{|byte|
> i+=1};print i}
> 794=> nil
> irb(main):003:0> File.size("tcpdump/al2ak_contents.dat")
> => 3329
> irb(main):004:0>
> File.open("tcpdump/al2ak_contents.dat"){|file|file.each_byte{|byte|
> };file.eof?}
> => true
>
> i should be equal to the size of the file. This is definitely a real
> difference. The file actually has 3329 bytes in it. That is what the
> OS thinks and something close to that is what opening the file shows.
>
> irb(main):019:0>
> File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|};file.pos}
> => 3329
>
> This implies that some bytes are being ignored or that each_byte just
> sets pos to file size at the end.
>
> irb(main):028:0>
> File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
> i+=1};file.seek(i);file.read;}
> => "\r\016\f\021\017\022\023\024\023\022\017\030\030"
> irb(main):029:0>
> File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
> i+=1};file.seek(i);file.read;file.eof}
> => true
> irb(main):030:0>
> File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
> i+=1};file.seek(i);file.read;file.eof;file.pos}
> => 1306
> irb(main):031:0>
> File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
> i+=1};file.seek(i);file.read.length}
> => 13
>
> So we are at eof after reading i bytes, as shown above, but I seek to
> i and then read another 13 bytes before eof again. But look at the
> huge chance in pos, which didn't go to 3329 this time. Let's try
> going to i+13
>
> irb(main):021:0>
> File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
> i+=1};file.seek(i+13);file.read;}
> => ""
> irb(main):022:0>
> File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
> i+=1};file.seek(i+13);file.read;file.eof;}
> => true
> irb(main):023:0>
> File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
> i+=1};file.seek(i+13);file.read;file.eof;file.pos}
> => 1319
>
> That sort of makes sense. If 1306 was actually the end of file, then
> adding 13 to it would produce exactly these results. Adding 14 to i
> has the same results as 13. Adding 15 to i has an different outcome:
>
> irb(main):043:0>
> File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
> i+=1};file.seek(i+15);file.read}
> =>
> "\030\030#\"\"\"#''''''''''\001\t\010\010\t\n\t\v\t\t\v\016\v\r\v\016\021\016
> \016\016\016\021\023\r\r\016\r\r\023\030\021\017\017\017\017\021\030\026\027\024
> \024\024\027\026"
> irb(main):044:0>
> File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
> i+=1};file.seek(i+15);file.read;file.eof}
> => true
> irb(main):045:0>
> File.open("tcpdump/al2ak_contents.dat"){|file|i=0;file.each_byte{|byte|
> i+=1};file.seek(i+15);file.read;file.eof;file.pos}
> => 1321
>
> So adding 15 to i returns a new string of bytes and gets an eof again
> and doesn't move the pos past 1306 + 15.
>
> I am at a loss for explaining what is going on here. Why can't
> each_byte get to the true eof? And why can I seek to the true eof (I
> didn't show it, but it worked) if each_byte can't make it there?
>
> Any help is appreciated. I'll try to answer any questions as well.
>
> Sincerely,
>
> Chris Parker

I guess this is a binary file. Those you should open in binary mode -
regardless of platform even if some platfors don't make a difference there.
Please recheck with open mode "rb" and let us know the outcome.

Kind regards

robert

Patriot Games

7/11/2007 1:29:00 PM

0

"robw" <noddy093@comcast.net> wrote in message
news:xM-dnftzC674sQnbnZ2dnUVZ_gOdnZ2d@comcast.com...
> And Busch has raised the bar.....how?

By not skull-fuck a girl his daughter's age in the Oval Office bathroom....

> "Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
> news:4693f4c7$0$15014$4c368faf@roadrunner.com...
>> "Amanda Williams" <pms@fu.com> wrote in message
>> news:Xns9969662DE373Afubar@63.218.45.252...
>> > Their hero, the guy who was going to restore "honor and dignity" to the
>> > Whitehouse ... "honor and dignity"...
>>
>> Bush didn't skull-fuck a girl his daughter's age in the Oval Office
>> bathroom....
>>
>> Bubba-Stiffy did.
>>
>>
>>
>>
>
>

robw

7/11/2007 3:12:00 PM

0

No, he's just lied his ways to thousands of needless deaths.


"Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
news:4694db00$0$12233$4c368faf@roadrunner.com...
> "robw" <noddy093@comcast.net> wrote in message
> news:xM-dnftzC674sQnbnZ2dnUVZ_gOdnZ2d@comcast.com...
> > And Busch has raised the bar.....how?
>
> By not skull-fuck a girl his daughter's age in the Oval Office
bathroom....
>
> > "Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
> > news:4693f4c7$0$15014$4c368faf@roadrunner.com...
> >> "Amanda Williams" <pms@fu.com> wrote in message
> >> news:Xns9969662DE373Afubar@63.218.45.252...
> >> > Their hero, the guy who was going to restore "honor and dignity" to
the
> >> > Whitehouse ... "honor and dignity"...
> >>
> >> Bush didn't skull-fuck a girl his daughter's age in the Oval Office
> >> bathroom....
> >>
> >> Bubba-Stiffy did.
> >>
> >>
> >>
> >>
> >
> >
>


WF Peifer

7/11/2007 4:16:00 PM

0

"Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
news:4694db00$0$12233$4c368faf@roadrunner.com...
> "robw" <noddy093@comcast.net> wrote in message
> news:xM-dnftzC674sQnbnZ2dnUVZ_gOdnZ2d@comcast.com...
> > And Busch has raised the bar.....how?
>
> By not skull-fuck a girl his daughter's age in the Oval Office
bathroom....

Skull-fucking a male prostitute is somehow more honorable and more
dignified?

--
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
"This is an impressive crowd - the haves and the have-mores. Some people
call you the elites; I call you my base." - George W. Bush


XMX

7/11/2007 11:00:00 PM

0


"Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
news:4693f4c7$0$15014$4c368faf@roadrunner.com...
> "Amanda Williams" <pms@fu.com> wrote in message
> news:Xns9969662DE373Afubar@63.218.45.252...
>> Their hero, the guy who was going to restore "honor and dignity" to the
>> Whitehouse ... "honor and dignity"...
>
> Bush didn't skull-fuck a girl his daughter's age in the Oval Office
> bathroom....
>
> Bubba-Stiffy did.

Excellent excuse of why G.W. bush is such a failure!

Good thing the Clinton didn't fart in public, that would be why bush gave
false information about Iraq. Oh wait, his hand picked people used 1998
information for invading Iraq. Yup, it's Clinton's fault.


WF Peifer

7/13/2007 1:20:00 AM

0

"Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
news:469628ed$0$24765$4c368faf@roadrunner.com...
> "WF Peifer" <WFPeifer@NoSpam.com> wrote in message
> news:opOdndIrbq8ayAjbnZ2dnUVZ_qarnZ2d@comcast.com...
> > "Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
> > news:4695516d$0$30604$4c368faf@roadrunner.com...
> >> "WF Peifer" <WFPeifer@NoSpam.com> wrote in message
> >> news:j6adnYD889FibgnbnZ2dnUVZ_s-rnZ2d@comcast.com...
> >> > "Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
> >> > news:4694db00$0$12233$4c368faf@roadrunner.com...
> >> >> "robw" <noddy093@comcast.net> wrote in message
> >> >> news:xM-dnftzC674sQnbnZ2dnUVZ_gOdnZ2d@comcast.com...
> >> >> > And Busch has raised the bar.....how?
> >> >> By not skull-fuck a girl his daughter's age in the Oval Office
> >> > bathroom....
> >> > Skull-fucking a male prostitute is somehow more honorable and more
> >> > dignified?
> >> Clinton did THAT too!?!?!?!?!?!
> > Nah. Gannon didn't show up with his leather pants with the butt cheeks
> > cut
> > out until 2003.
>
> This is getting confusing. You're saying Clinton WOULD HAVE skull-fucked
a
> male prostitute with "leather pants with the butt cheeks cut out" IF he
had
> the chance, but he didn't have the chance?

I must apologize if I'm confusing you. I keep forgetting that posts
directed toward a right-winger need to be explained in more detail to
compensate for the lower level of cognitive abilities. What I'm saying is
that, had Jeff Gannon shown up 3 years earlier, Clinton would have had him
unceremoniously booted out into the middle of Pennsylvania Avenue. It took
the neo-con crowd coming to power before the "special talents" that you and
he possess could be appreciated by anyone in the White House.

--
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
"This is an impressive crowd - the haves and the have-mores. Some people
call you the elites; I call you my base." - George W. Bush


robw

7/13/2007 2:52:00 AM

0

He wasn;t in 2006, either.

How'd that turn out?


"Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
news:469621e4$0$4896$4c368faf@roadrunner.com...
> "robw" <noddy093@comcast.net> wrote in message
> news:J_idnc2IJ-7f_QjbnZ2dnUVZ_tCdnZ2d@comcast.com...
> > Nov. 7th 2006.
> > His approval numbers now.
> > Nov. 6th 2008?
> > We'll see.
>
> I can help you with that. Bush isn't running for
> re-election....................
>
> > "Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
> > news:469550f0$0$12213$4c368faf@roadrunner.com...
> >> "robw" <noddy093@comcast.net> wrote in message
> >> news:-IKdnc3IyMSAbgnbnZ2dnUVZ_gydnZ2d@comcast.com...
> >> > No, he's just lied his ways to thousands of needless deaths.
> >>
> >> Where are the charges? <crickets...>
> >>
> >> Where are the warrants? <crickets...>
> >>
> >> Where are the indictments? <crickets...>
> >>
> >> Articles of impeachment? <crickets...>
> >>
> >> Nowhere. Because there is NO proof of lies...
> >>
> >> Wise up, wouldya?
> >>
> >> > "Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
> >> > news:4694db00$0$12233$4c368faf@roadrunner.com...
> >> >> "robw" <noddy093@comcast.net> wrote in message
> >> >> news:xM-dnftzC674sQnbnZ2dnUVZ_gOdnZ2d@comcast.com...
> >> >> > And Busch has raised the bar.....how?
> >> >>
> >> >> By not skull-fuck a girl his daughter's age in the Oval Office
> >> > bathroom....
> >> >>
> >> >> > "Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
> >> >> > news:4693f4c7$0$15014$4c368faf@roadrunner.com...
> >> >> >> "Amanda Williams" <pms@fu.com> wrote in message
> >> >> >> news:Xns9969662DE373Afubar@63.218.45.252...
> >> >> >> > Their hero, the guy who was going to restore "honor and
dignity"
> > to
> >> > the
> >> >> >> > Whitehouse ... "honor and dignity"...
> >> >> >>
> >> >> >> Bush didn't skull-fuck a girl his daughter's age in the Oval
Office
> >> >> >> bathroom....
> >> >> >>
> >> >> >> Bubba-Stiffy did.
> >> >> >>
> >> >> >>
> >> >> >>
> >> >> >>
> >> >> >
> >> >> >
> >> >>
> >> >
> >> >
> >>
> >
> >
>


Patriot Games

7/13/2007 1:30:00 PM

0

"robw" <noddy093@comcast.net> wrote in message
news:DaSdnb2O5rl1dQvbnZ2dnUVZ_jednZ2d@comcast.com...
> He wasn;t in 2006, either.
> How'd that turn out?

Very bad... 60% of registered voters didn't bother to vote...

> "Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
> news:469621e4$0$4896$4c368faf@roadrunner.com...
>> "robw" <noddy093@comcast.net> wrote in message
>> news:J_idnc2IJ-7f_QjbnZ2dnUVZ_tCdnZ2d@comcast.com...
>> > Nov. 7th 2006.
>> > His approval numbers now.
>> > Nov. 6th 2008?
>> > We'll see.
>>
>> I can help you with that. Bush isn't running for
>> re-election....................
>>
>> > "Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
>> > news:469550f0$0$12213$4c368faf@roadrunner.com...
>> >> "robw" <noddy093@comcast.net> wrote in message
>> >> news:-IKdnc3IyMSAbgnbnZ2dnUVZ_gydnZ2d@comcast.com...
>> >> > No, he's just lied his ways to thousands of needless deaths.
>> >>
>> >> Where are the charges? <crickets...>
>> >>
>> >> Where are the warrants? <crickets...>
>> >>
>> >> Where are the indictments? <crickets...>
>> >>
>> >> Articles of impeachment? <crickets...>
>> >>
>> >> Nowhere. Because there is NO proof of lies...
>> >>
>> >> Wise up, wouldya?
>> >>
>> >> > "Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
>> >> > news:4694db00$0$12233$4c368faf@roadrunner.com...
>> >> >> "robw" <noddy093@comcast.net> wrote in message
>> >> >> news:xM-dnftzC674sQnbnZ2dnUVZ_gOdnZ2d@comcast.com...
>> >> >> > And Busch has raised the bar.....how?
>> >> >>
>> >> >> By not skull-fuck a girl his daughter's age in the Oval Office
>> >> > bathroom....
>> >> >>
>> >> >> > "Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
>> >> >> > news:4693f4c7$0$15014$4c368faf@roadrunner.com...
>> >> >> >> "Amanda Williams" <pms@fu.com> wrote in message
>> >> >> >> news:Xns9969662DE373Afubar@63.218.45.252...
>> >> >> >> > Their hero, the guy who was going to restore "honor and
> dignity"
>> > to
>> >> > the
>> >> >> >> > Whitehouse ... "honor and dignity"...
>> >> >> >>
>> >> >> >> Bush didn't skull-fuck a girl his daughter's age in the Oval
> Office
>> >> >> >> bathroom....
>> >> >> >>
>> >> >> >> Bubba-Stiffy did.
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >
>> >> >> >
>> >> >>
>> >> >
>> >> >
>> >>
>> >
>> >
>>
>
>

Patriot Games

7/13/2007 1:31:00 PM

0

"Bugman" <jmposing@hotmail.com> wrote in message
news:3OSdnefdyMDBvgvbnZ2dnUVZ_vqpnZ2d@giganews.com...
> "Patriot Games" <Crazy_Bastard@The_Beach.com> wrote in message
> news:46962253$0$20567$4c368faf@roadrunner.com...
>> "robw" <noddy093@comcast.net> wrote in message
>> news:-eSdnX6K0-NTwgjbnZ2dnUVZ_hadnZ2d@comcast.com...
>>> Not the point.
>>> The response to "a girl his daughter's age" is what's at play here.
>>> Monika was not Chelsea's age when it happened.
>>> But you have to spin........
>>> And Clinton was in his fifties....so what?
>> So, its age-inappropriate, that's what. Its borderline pedophilia.
> Fred Thompson and his grand-daughter/wife.

What's her age?