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).
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?
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
All of the ptools methods are cross-platform so yes, File.binary? will work fine on Unix.
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.
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?