class Uploader::Upload::Put::Chunker

Public Class Methods

new(sock, content_length, handlers) click to toggle source
# File lib/ruby-uploader/uploader.rb, line 74
def initialize(sock, content_length, handlers)
  @sock = sock
  @prev = nil
  @count = 0
  @total_count = nil
  @content_length = content_length.to_i
  @handlers = handlers
end

Public Instance Methods

finish() click to toggle source
# File lib/ruby-uploader/uploader.rb, line 105
def finish
  @sock.write("0\r\n\r\n")
end
write(buf) click to toggle source
# File lib/ruby-uploader/uploader.rb, line 83
def write(buf)
  @total_count = @content_length / buf.bytesize.to_i if @total_count.nil?

  @handlers[:before_chunk].each do |handler|
    handler.execute buf, @count, @total_count, @content_length
  end

  puts "#{@count} / #{@total_count}"

  @sock.write("#{buf.bytesize.to_s(16)}\r\n")
  rv = @sock.write(buf)
  @sock.write("\r\n")

  @count += 1

  @handlers[:after_chunk].each do |handler|
    handler.execute buf, @count, @total_count, @content_length
  end

  rv
end