# \- ptools 1.1.1

**URL:** <https://www.ruby-forum.com/t/ptools-1-1-1/66201>\
**Category:** Ruby\
**Created:** [August 23, 2006, 10:42pm UTC](https://www.ruby-forum.com/t/ptools-1-1-1/66201 "2006-08-23T22:42:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [August 23, 2006, 10:42pm UTC](https://www.ruby-forum.com/t/ptools-1-1-1/66201/1 "2006-08-23T22:42:34Z")

</div>

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://raa.ruby-lang.org/project/ptools/)  
[http://rubyforge.org/projects/shards/](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.

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [August 24, 2006, 5:07am UTC](https://www.ruby-forum.com/t/ptools-1-1-1/66201/2 "2006-08-24T05:07:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [August 24, 2006, 5:15am UTC](https://www.ruby-forum.com/t/ptools-1-1-1/66201/3 "2006-08-24T05:15:04Z")

</div>

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. 🙂

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [August 24, 2006, 6:19am UTC](https://www.ruby-forum.com/t/ptools-1-1-1/66201/4 "2006-08-24T06:19:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [August 24, 2006, 6:11am UTC](https://www.ruby-forum.com/t/ptools-1-1-1/66201/5 "2006-08-24T06:11:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [August 24, 2006, 6:23am UTC](https://www.ruby-forum.com/t/ptools-1-1-1/66201/6 "2006-08-24T06:23:09Z")

</div>

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. 🙂

Are you assuming Unicode, ASCII, or what?

Hal

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [August 24, 2006, 9:57am UTC](https://www.ruby-forum.com/t/ptools-1-1-1/66201/7 "2006-08-24T09:57:29Z")

</div>

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](http://subversion.tigris.org/faq.html#binary-files)

– fxn

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [August 24, 2006, 9:53am UTC](https://www.ruby-forum.com/t/ptools-1-1-1/66201/8 "2006-08-24T09:53:28Z")

</div>

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. 🙂
> 
> Are you assuming Unicode, ASCII, or what?

What is the heuristic used by Subversion for instance?

– fxn
