Sha256: 78e46bf772b813d8aa1ee4367338072438509a31792238ef21a684ac912b76f6

Contents?: true

Size: 1.31 KB

Versions: 28

Compression:

Stored size: 1.31 KB

Contents

# -*- coding: utf-8 -*-

class WriteFile
  def initialize
    @data            = ''
    @datasize        = 0
    @limit           = 8224

    # Open a tmp file to store the majority of the Worksheet data. If this fails,
    # for example due to write permissions, store the data in memory. This can be
    # slow for large files.
    @filehandle = Tempfile.new('writeexcel')
    @filehandle.binmode

    # failed. store temporary data in memory.
    @using_tmpfile = @filehandle ? true : false
  end

  ###############################################################################
  #
  # _prepend($data)
  #
  # General storage function
  #
  def prepend(*args)
    data = join_data(args)
    @data = data + @data

    data
  end

  ###############################################################################
  #
  # _append($data)
  #
  # General storage function
  #
  def append(*args)
    data = join_data(args)

    if @using_tmpfile
      @filehandle.write(data)
    else
      @data += data
    end

    data
  end

  private

  def join_data(args)
    data =
      ruby_18 { args.join } ||
      ruby_19 { args.compact.collect{ |arg| arg.dup.force_encoding('ASCII-8BIT') }.join }
    # Add CONTINUE records if necessary
    data = add_continue(data) if data.bytesize > @limit

    @datasize += data.bytesize

    data
  end
end

Version data entries

28 entries across 28 versions & 3 rubygems

Version Path
writeexcel-1.0.9 lib/writeexcel/write_file.rb
writeexcel-1.0.8 lib/writeexcel/write_file.rb
writeexcel-1.0.7 lib/writeexcel/write_file.rb
writeexcel-1.0.6 lib/writeexcel/write_file.rb
writeexcel-1.0.5 lib/writeexcel/write_file.rb
writeexcel-1.0.4 lib/writeexcel/write_file.rb
writeexcel-1.0.3 lib/writeexcel/write_file.rb
writeexcel-1.0.2 lib/writeexcel/write_file.rb
writeexcel-1.0.1 lib/writeexcel/write_file.rb
writeexcel-1.0.0 lib/writeexcel/write_file.rb
writeexcel-0.6.19 lib/writeexcel/write_file.rb
writeexcel-0.6.18 lib/writeexcel/write_file.rb
writeexcel-0.6.17 lib/writeexcel/write_file.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/writeexcel-0.6.16/lib/writeexcel/write_file.rb
writeexcel-0.6.16 lib/writeexcel/write_file.rb
writeexcel-0.6.15 lib/writeexcel/write_file.rb
writeexcel-0.6.14 lib/writeexcel/write_file.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/writeexcel-0.6.13/lib/writeexcel/write_file.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/writeexcel-0.6.13/lib/writeexcel/write_file.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/writeexcel-0.6.13/lib/writeexcel/write_file.rb