File.read() v Pathname.read() gotcha

This email has been sent in HTML mode. In order to view this email, please activate HTML message viewing.

"Returns all data from the file, or the first N bytes if specified."

Best,
Christian

···

Sent from my iPhone

On 1 Jun 2017, at 17:41, Paul Kuruvilla <rohitpaulk@gmail.com<mailto:rohitpaulk@gmail.com>> wrote:

From the docs<https://www.advmailservice.com/l/86aaa96746e011e783e5005056a3018b>: "Pathname<https://www.advmailservice.com/l/86b2594a46e011e783e5005056a3018b> is immutable".

Regards,
Paul

On Thu, Jun 1, 2017 at 8:48 PM, Andy Jones <Andy.Jones@jameshall.co.uk<https://www.advmailservice.com/l/86b6ff0346e011e783e5005056a3018b>> wrote:
This is damned annoying. And does not appear to be documented, at least, obviously.

Given a file:
    111222333444555

Then File.read and IO.read work like this:

    f = File.new("filename")
    f.read(3) # -> "111"
    f.read(3) # -> "222"
    f.read(3) # -> "333"

But look what happens when I use Pathname instead of File:

    p = Pathname.new("filename")
    p.read(3) # -> "111"
    p.read(3) # -> "111"
    p.read(3) # -> "111"

But according to the docs for Pathname.read(), it's just a proxy for File.read()...

Click here to view Company Information and Confidentiality Notice.<http://www.jameshall.co.uk/index.php/small-print/email-disclaimer<https://www.advmailservice.com/l/86bbae5146e011e783e5005056a3018b>>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org<https://www.advmailservice.com/l/86c0ce4946e011e783e5005056a3018b>?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk<https://www.advmailservice.com/l/86c5979646e011e783e5005056a3018b>>

[https://www.advmailservice.com/b/8679000546e011e783e5005056a3018b.png]

Well, okay. But if that’s the only clue we get, that’s pretty subtle. It also says:

Ø All functionality from File, FileTest, and some from Dir and FileUtils

Ø is included, in an unsurprising way.

Which is arguably not true, in two ways…

···

From: ruby-talk [mailto:ruby-talk-bounces@ruby-lang.org] On Behalf Of Paul Kuruvilla
Sent: 01 June 2017 16:41
To: ruby users
Subject: Re: File.read() v Pathname.read() gotcha

From the docs<https://www.advmailservice.com/l/86aaa96746e011e783e5005056a3018b>: "Pathname<https://www.advmailservice.com/l/86b2594a46e011e783e5005056a3018b> is immutable".

Regards,
Paul

On Thu, Jun 1, 2017 at 8:48 PM, Andy Jones <Andy.Jones@jameshall.co.uk<https://www.advmailservice.com/l/86b6ff0346e011e783e5005056a3018b>> wrote:
This is damned annoying. And does not appear to be documented, at least, obviously.

Given a file:
    111222333444555

Then File.read and IO.read work like this:

    f = File.new("filename")
    f.read(3) # -> "111"
    f.read(3) # -> "222"
    f.read(3) # -> "333"

But look what happens when I use Pathname instead of File:

    p = Pathname.new("filename")
    p.read(3) # -> "111"
    p.read(3) # -> "111"
    p.read(3) # -> "111"

But according to the docs for Pathname.read(), it's just a proxy for File.read()...

Click here to view Company Information and Confidentiality Notice.<http://www.jameshall.co.uk/index.php/small-print/email-disclaimer<https://www.advmailservice.com/l/86bbae5146e011e783e5005056a3018b>>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org<https://www.advmailservice.com/l/86c0ce4946e011e783e5005056a3018b>?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk<https://www.advmailservice.com/l/86c5979646e011e783e5005056a3018b>>

[Image removed by sender.]

Click here to view Company Information and Confidentiality Notice.<http://www.jameshall.co.uk/index.php/small-print/email-disclaimer>

Please stop sending such nonsense mails! Either include a text/plain
part that has a meaning, or leave it off entirely. But do not send such
a nonsense notice in it. It's multipart/ALTERNATIVE, not
multipart/NOTHING_VALUABLE_HERE! If you do not offer an equal
*alternative*, then do not include the text/plain part. This prevents
autoformatters from detecting the HTML part and automatically dumping it
to plaintext (using e.g. Lynx).

Sorry for the OT, but I couldn't let this go.

Marvin

···

On Thu, Jun 01, 2017 at 08:40:52AM -0700, Paul Kuruvilla wrote:

This email has been sent in HTML mode. In order to view this email,
please activate HTML message viewing.

--
Blog: https://www.guelkerdev.de
PGP/GPG ID: F1D8799FBCC8BC4F

I agree. I have that same problem with a few automated emails I get (ones
that I actually care somewhat about). Mutt and lynx/links/w3m work well
enough for most HTML emails, if they just know enough about a message to
convert the HTML automatically. This kind of placeholder defeats that
feature.

···

On Thu, Jun 1, 2017 at 1:40 PM, Marvin Gülker <m-guelker@phoenixmail.de> wrote:

On Thu, Jun 01, 2017 at 08:40:52AM -0700, Paul Kuruvilla wrote:
> This email has been sent in HTML mode. In order to view this email,
> please activate HTML message viewing.

Please stop sending such nonsense mails! Either include a text/plain
part that has a meaning, or leave it off entirely. But do not send such
a nonsense notice in it. It's multipart/ALTERNATIVE, not
multipart/NOTHING_VALUABLE_HERE! If you do not offer an equal
*alternative*, then do not include the text/plain part. This prevents
autoformatters from detecting the HTML part and automatically dumping it
to plaintext (using e.g. Lynx).

Sorry for the OT, but I couldn't let this go.

Marvin

--
        Eric Christopherson

Sorry about that, didn't realise that a plugin I had active was doing that
behind the scenes.

···

On 2 Jun 2017 1:22 a.m., "Eric Christopherson" <echristopherson@gmail.com> wrote:

On Thu, Jun 1, 2017 at 1:40 PM, Marvin Gülker <m-guelker@phoenixmail.de> > wrote:

On Thu, Jun 01, 2017 at 08:40:52AM -0700, Paul Kuruvilla wrote:
> This email has been sent in HTML mode. In order to view this email,
> please activate HTML message viewing.

Please stop sending such nonsense mails! Either include a text/plain
part that has a meaning, or leave it off entirely. But do not send such
a nonsense notice in it. It's multipart/ALTERNATIVE, not
multipart/NOTHING_VALUABLE_HERE! If you do not offer an equal
*alternative*, then do not include the text/plain part. This prevents
autoformatters from detecting the HTML part and automatically dumping it
to plaintext (using e.g. Lynx).

Sorry for the OT, but I couldn't let this go.

Marvin

I agree. I have that same problem with a few automated emails I get (ones
that I actually care somewhat about). Mutt and lynx/links/w3m work well
enough for most HTML emails, if they just know enough about a message to
convert the HTML automatically. This kind of placeholder defeats that
feature.

--
        Eric Christopherson

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;