Parent

Methods

Files

MogileFS::Chunker

Constants

CRLF

Attributes

io[R]

Public Class Methods

new(io, md5, expect_md5) click to toggle source
# File lib/mogilefs/chunker.rb, line 5
def initialize(io, md5, expect_md5)
  @io = io
  @md5 = md5
  @expect_md5 = expect_md5
end

Public Instance Methods

flush() click to toggle source
# File lib/mogilefs/chunker.rb, line 20
def flush
  if @md5
    content_md5 = [ @md5.digest ].pack('m').rstrip!
    if @expect_md5.respond_to?(:call)
      expect = @expect_md5.call.strip
      if expect != content_md5
        raise MogileFS::ChecksumMismatchError,
          "expected: #{expect.inspect} actual: #{content_md5.inspect}"
      end
    end
    @io.write("0\r\nContent-MD5: #{content_md5}\r\n\r\n")
  else
    @io.write("0\r\n\r\n")
  end
end
write(buf) click to toggle source
# File lib/mogilefs/chunker.rb, line 11
def write(buf)
  rv = buf.bytesize
  @io.write("#{rv.to_s(16)}\r\n")
  @io.write(buf)
  @md5.update(buf) if @md5
  @io.write(CRLF)
  rv
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.