- ptools 1.1.1

Hi all,

This is just a quick announcement to let y’all know that I’ve released
ptools
1.1.1 today.

What is it?

Power tools for the File class. Additional methods include which,
whereis,
head, tail, middle, wc, null, nl_convert, touch and binary?.

What’s new?

This release adds the File.null and File.binary? methods. The former
returns
the null device on your system The latter returns whether or not the
file in
question is a binary file (using a simple best-guess algorithm).

Where is it?

You can get it via gems, the RAA or RubyForge.

gem install ptools
http://raa.ruby-lang.org/project/ptools/
http://rubyforge.org/projects/shards/

Enjoy!

  • Dan

PS - I forgot to put the dependency in the gem, but Windows users will
need
win32-file-stat. If you’re using the latest one-click installer, you’ve
already got it.

This communication is the property of Qwest and may contain confidential
or
privileged information. Unauthorized use of this communication is
strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and
destroy
all copies of the communication and any attachments.

fr daniel:

Power tools for the File class. Additional methods include

which, whereis,

head, tail, middle, wc, null, nl_convert, touch and binary?.

very cool and helpful. now win users aren’t left so far behind…

maybe, i can create a more efficient grep -r now, one that does not
include binary files. Will #binary? work on unix too?

thanks for ptools -botp

Peña wrote:

All of the ptools methods are cross-platform so yes, File.binary? will
work fine on Unix.

Glad you’re enjoying it. :slight_smile:

Regards,

Dan

fr Paul:

A variation on “binary?” might read a file to see if it

deviates from 7-bit

ASCII, but this will fail for perfectly valid Unicode text

files. So IMHO it’s a bad idea.

ah, maybe i should state my problem better, how about “i’d like to know
if a file is a pure text file”. how should i do that in ruby?

thanks and kind regards -botp

Peña, Botp wrote:

fr daniel:

Power tools for the File class. Additional methods include

which, whereis,

head, tail, middle, wc, null, nl_convert, touch and binary?.

very cool and helpful. now win users aren’t left so far behind…

maybe, i can create a more efficient grep -r now, one that does not
include binary files. Will #binary? work on unix too?

Yep. In a *nix file read/write context, specifying binary does nothing,
because Unix doesn’t honor the distinction, so the test “binary?” should
always “work”. It is only meaningful in Windows.

In fact, the entire “binary” idea was created to deal with the weird
Windows
line endings. If “binary” is specified, the file read/write system stops
translating “\n\r” to “\n” on read, and “\n” to “\n\r” on write. That’s
all.

A variation on “binary?” might read a file to see if it deviates from
7-bit
ASCII, but this will fail for perfectly valid Unicode text files. So
IMHO
it’s a bad idea.

Peña wrote:

ah, maybe i should state my problem better, how about “i’d like to know if a file is a pure text file”. how should i do that in ruby?

That depends on what you mean by a pure text file. :slight_smile:

Are you assuming Unicode, ASCII, or what?

Hal

On Aug 24, 2006, at 9:52 AM, Xavier N. wrote:

Are you assuming Unicode, ASCII, or what?

What is the heuristic used by Subversion for instance?

Ah, yes, it is in their FAQ:

http://subversion.tigris.org/faq.html#binary-files

– fxn

On Aug 24, 2006, at 6:21 AM, Hal F. wrote:

Peña wrote:

ah, maybe i should state my problem better, how about “i’d like to
know if a file is a pure text file”. how should i do that in ruby?

That depends on what you mean by a pure text file. :slight_smile:

Are you assuming Unicode, ASCII, or what?

What is the heuristic used by Subversion for instance?

– fxn