Module: Utils::FileXt

Extended by:
DSLKit::Concern
Includes:
File::Constants
Included in:
File
Defined in:
lib/utils/file_xt.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

SEEK_SET =
File::SEEK_SET
ZERO =
"\x00"
BINARY =
"\x01-\x1f\x7f-\xff"

Instance Method Summary collapse

Instance Method Details

#ascii?Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
# File 'lib/utils/file_xt.rb', line 29

def ascii?
  case binary?
  when true   then false
  when false  then true
  end
end

#binary?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
# File 'lib/utils/file_xt.rb', line 18

def binary?
  old_pos = tell
  seek 0, SEEK_SET
  data = read 2 ** 13
  !data or data.empty? and return nil
  data.count(ZERO) > 0 and return true
  data.count(BINARY).to_f / data.size > 0.3
ensure
  seek old_pos, SEEK_SET
end