ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de>
Subject RE: Testing a file if it is binary or not.
Date Tue, 21 Aug 2007 10:31:21 GMT

Hi,

-----Original Message-----
From: Ditrick, Gregory [mailto:gregory.ditrick@fmr.com] 
Sent: Monday, August 20, 2007 9:01 PM
To: Ant Users List
Subject: Testing a file if it is binary or not.

/*
Does anyone have any ideas other than using the files extension as a
guide
and praying that you have them correct and don't miss any?  Yuck!

CVS requires you to designate the file type as binary fro binary files
when adding the file.  Other SCM usually handle this internally.
*/

Subversion does it like that =
http://subversion.tigris.org/faq.html#binary-files

so maybe =

<target name="init">
  
    <script language="ruby">
      <![CDATA[
      class File
        def self.binary?(name)
          ascii = total = 0
            File.open(name, "rb") { |io| io.read(1024) }.each_byte do
|c|
              total += 1; 
              ascii +=1 if c >= 128  or c == 0
            end
            ascii.to_f / total.to_f > 0.15
        end
      end
      
      puts File.binary?("Y:/bla.zip")
      
      File.binary?("Y:/bla.zip") ? 
      ($project.setProperty "isbinary", "true") : ($project.setProperty
"isascii", "true")
      ]]>
    </script>			
  
  </target>
  
    <target name="main" depends="init">
    <echo>
      $${isbinary} == ${isbinary}
      $${isascii}  == ${isascii}
    </echo>
    </target>


init:
   [script] true
main:
     [echo] ${isbinary} == true
     [echo] ${isascii}  == ${isascii}
BUILD SUCCESSFUL
Total time: 3 seconds




Regards, Gilbert




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message