Search
Project
General
Profile
Home
Projects
Help
Sign in
Register
Search
:
Redmine
All Projects
Redmine
Overview
Download
Activity
Roadmap
Issues
News
Wiki
Plugins
Forums
Repository
Download (423 Bytes)
RE: when trying to open files in repository,but downloadi...
ยป binary.rb
Victor Gavro
, 2010-08-31 17:35
#!/usr/bin/env ruby
# run me like ruby binary.rb /PATH/TO/FILE
# this scripts checks if the file contains binary or textual data.
# thanks meineerde for help
require
'yaml'
FILENAME
=
ARGV
[
0
]
f
=
File
.
read
(
FILENAME
)
binary
=
f
.
is_binary_data?
binary_koef
=
f
.
count
(
"^ -~"
,
"^
\r\n
"
).
fdiv
(
f
.
size
)
puts
"The file
#{
FILENAME
}
contains
#{
binary
?
"BINARY"
:
"TEXTUAL"
}
data."
puts
"file is binary if
#{
binary_koef
}
> 0.3"
(1-1/1)
Loading...