<commit_before># -*- encoding: us-ascii -*-

class IO
  attr_accessor :external
  attr_accessor :internal

  module WaitReadable; end
  module WaitWritable; end

  class EAGAINWaitReadable < Errno::EAGAIN
    include ::IO::WaitReadable
  end

  class EAGAINWaitWritable < Errno::EAGAIN
    include ::IO::WaitWritable
  end

  def self.binread(file, length=nil, offset=0)
    raise ArgumentError, "Negative length #{length} given" if !length.nil? && length < 0

    File.open(file, "rb") do |f|
      f.seek(offset)
      f.read(length)
    end
  end

  def self.binwrite(file, string, offset=nil)
    mode = (offset.nil? || !File.file?(file)) ? "wb:ASCII-8BIT" : "rb+:ASCII-8BIT"
    File.open(file, mode) do |f|
      f.seek(offset || 0)
      f.write(string)
    end
  end

  def self.write(file, string, offset=nil)
    mode = (offset.nil? || !File.file?(file)) ? "w:ASCII-8BIT" : "r+:ASCII-8BIT"
    File.open(file, mode) do |f|
      f.seek(offset || 0)
      f.write(string)
    end
  end

  def self.for_fd(fd, mode=undefined, options=undefined)
    new fd, mode, options
  end

  def self.read(name, length_or_options=undefined, offset=0, options=nil)
    offset = 0 if offset.nil?
    name = Rubinius::Type.coerce_to_path name
    mode = "r"

    if length_or_options.equal? undefined
      length = undefined<commit_msg>IO::binwrite with more understandable file open logic<commit_after># -*- encoding: us-ascii -*-

class IO
  attr_accessor :external
  attr_accessor :internal

  module WaitReadable; end
  module WaitWritable; end

  class EAGAINWaitReadable < Errno::EAGAIN
    include ::IO::WaitReadable
  end

  class EAGAINWaitWritable < Errno::EAGAIN
    include ::IO::WaitWritable
  end

  def self.binread(file, length=nil, offset=0)
    raise ArgumentError, "Negative length #{length} given" if !length.nil? && length < 0

    File.open(file, "rb") do |f|
      f.seek(offset)
      f.read(length)
    end
  end

  def self.binwrite(file, string, offset=nil)
    mode = File::CREAT | File::RDWR
    mode |= File::TRUNC unless offset
    File.open(file, mode, :encoding => "ASCII-8BIT") do |f|
      f.seek(offset || 0)
      f.write(string)
    end
  end

  def self.write(file, string, offset=nil)
    mode = (offset.nil? || !File.file?(file)) ? "w:ASCII-8BIT" : "r+:ASCII-8BIT"
    File.open(file, mode) do |f|
      f.seek(offset || 0)
      f.write(string)
    end
  end

  def self.for_fd(fd, mode=undefined, options=undefined)
    new fd, mode, options
  end

  def self.read(name, length_or_options=undefined, offset=0, options=nil)
    offset = 0 if offset.nil?
    name = Rubinius::Type.coerce_to_path name
    mode = "r"

    if length_or_options.equal? undefined
      length = undefined
{'fraction_non_alphanumeric': 0.1309786607799853, 'fraction_numerical': 0.006990434142752024, 'mean_word_length': 3.2484375, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5071471', 'n_tokens_mistral': 993, 'n_tokens_neox': 959, 'n_words': 235}