<commit_before># This code is free software; you can redistribute it and/or modify it under
# the terms of the new BSD License.
#
# Copyright (c) 2011, <NAME>

require 'stringio'

class RBzip2::Decompressor

  include RBzip2::Constants

  def initialize(io)
    @buff = 0
    @bytes_read = 0
    @computed_combined_crc = 0
    @crc = RBzip2::CRC.new
    @current_char = -1
    @io = io
    @live = 0
    @stored_combined_crc = 0
    @su_t_pos = 0
    init
  end

  def count(read)
    @bytes_read += read if read != -1
  end

  def read(length = nil)
    raise 'stream closed' if @io.nil?

    if length == 1
      r = read0
      count (r < 0 ? -1 : 1)
      r
    else
      r = StringIO.new
      if length == nil
        while true do
          b = read0
          break if b < 0
          r.write b.chr
        end
      elsif length > 0
        length.times do
          b = read0
          break if b < 0
          r.write b.chr
        end
        count r.size
      end
      r.string
    end
  end

  def read0
    ret_char = @current_char

    case @current_state
      when EOF
        return -1

      when RAND_PART_B_STATE
        setup_rand_part_b

      when RAND_PART_C_STATE<commit_msg>Use a simple String in Decompressor#read<commit_after># This code is free software; you can redistribute it and/or modify it under
# the terms of the new BSD License.
#
# Copyright (c) 2011, <NAME>

class RBzip2::Decompressor

  include RBzip2::Constants

  def initialize(io)
    @buff = 0
    @bytes_read = 0
    @computed_combined_crc = 0
    @crc = RBzip2::CRC.new
    @current_char = -1
    @io = io
    @live = 0
    @stored_combined_crc = 0
    @su_t_pos = 0
    init
  end

  def count(read)
    @bytes_read += read if read != -1
  end

  def read(length = nil)
    raise 'stream closed' if @io.nil?

    if length == 1
      r = read0
      count (r < 0 ? -1 : 1)
      r
    else
      r = ''
      if length == nil
        while true do
          b = read0
          break if b < 0
          r << b.chr
        end
      elsif length > 0
        length.times do
          b = read0
          break if b < 0
          r << b.chr
        end
        count r.size
      end
      r
    end
  end

  def read0
    ret_char = @current_char

    case @current_state
      when EOF
        return -1

      when RAND_PART_B_STATE
        setup_rand_part_b

      when RAND_PART_C_STATE
{'fraction_non_alphanumeric': 0.07560568086883876, 'fraction_numerical': 0.022556390977443608, 'mean_word_length': 1.6405733186328555, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 7, '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': '2730055', 'n_tokens_mistral': 872, 'n_tokens_neox': 813, 'n_words': 267}