Module: Spruz::FileBinary

### Home Classes Methods

### In Files

- lib/spruz/file_binary.rb

### Namespace

- MODULE Spruz::FileBinary::ClassMethods
- MODULE Spruz::FileBinary::Constants

### Methods

- ::included
- #ascii?
- #binary?

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Spruz
- Spruz::Attempt
- Spruz::Bijection
- Spruz::Blank
- Spruz::Blank::Array
- Spruz::Blank::FalseClass
- Spruz::Blank::Hash
- Spruz::Blank::NilClass
- Spruz::Blank::Numeric
- Spruz::Blank::Object
- Spruz::Blank::String
- Spruz::Blank::TrueClass
- Spruz::CountBy
- Spruz::DeepDup
- Spruz::FileBinary
- Spruz::FileBinary::ClassMethods
- Spruz::FileBinary::Constants
- Spruz::Full
- Spruz::GO
- Spruz::Generator
- Spruz::HashSymbolizeKeysRecursive
- Spruz::HashUnion
- Spruz::Limited
- Spruz::LinesFile
- Spruz::LinesFile::LineExtension
- Spruz::Memoize
- Spruz::Minimize
- Spruz::ModuleGroup
- Spruz::Null
- Spruz::Once
- Spruz::P
- Spruz::PartialApplication
- Spruz::RangePlus
- Spruz::Round
- Spruz::SecureWrite
- Spruz::Shuffle
- Spruz::StringCamelize
- Spruz::StringUnderscore
- Spruz::StringVersion
- Spruz::StringVersion::Version
- Spruz::Subhash
- Spruz::TimeDummy
- Spruz::TimeDummy::ClassMethods
- Spruz::ToProc
- Spruz::UniqBy
- Spruz::Write
- Array
- Enumerable
- File
- Float
- Hash
- IO
- IRB
- Integer
- Method
- Module
- Object
- Proc
- Range
- String
- Symbol
- Time

No matching classes.

# Spruz::FileBinary

### Attributes

default_options[RW]

Default options can be queried/set via this hash.

### Public Class Methods

included(modul) click to toggle source

    # File lib/spruz/file_binary.rb, line 62
    def self.included(modul)
      modul.instance_eval do
        extend ClassMethods
      end
      super
    end

### Public Instance Methods

ascii?(options = {}) click to toggle source

Returns true if FileBinary#binary? returns false, false if FileBinary#binary? returns true, and nil otherwise. For an explanation of `options`, see FileBinary#binary?.

    # File lib/spruz/file_binary.rb, line 55
    def ascii?(options = {})
      case binary?(options)
      when true   then false
      when false  then true
      end
    end

binary?(options = {}) click to toggle source

Returns true if this file is considered to be binary, false if it is not considered to be binary, and nil if it was empty.

A file is considered to be binary if the percentage of zeros exceeds `options[:percentage_zeros]` or the percentage of binary bytes (8-th bit is 1) exceeds `options[:percentage_binary]` in the buffer of size `options[:buffer_size]` that is checked (beginning from offset `options[:offset]`). If an option isn't given the one from FileBinary.default_options is used instead.

    # File lib/spruz/file_binary.rb, line 37
    def binary?(options = {})
      options |= FileBinary.default_options
      old_pos = tell
      seek options[:offset], Constants::SEEK_SET
      data = read options[:buffer_size]
      !data or data.empty? and return nil
      data_size = data.size
      data.count(Constants::ZERO).to_f / data_size >
        options[:percentage_zeros] / 100.0 and return true
      data.count(Constants::BINARY).to_f / data_size >
        options[:percentage_binary] / 100.0
    ensure
      old_pos and seek old_pos, Constants::SEEK_SET
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.