Class: Yahns::ChunkBody

Inherits:
Object
  • Object
show all
Defined in:
lib/yahns/chunk_body.rb

Overview

Copyright © 2016 all contributors <[email protected]> License: GPL-3.0+ <www.gnu.org/licenses/gpl-3.0.txt> frozen_string_literal: true

Instance Method Summary collapse

Constructor Details

#initialize(body, vec) ⇒ ChunkBody

:nodoc:



7
8
9
10
# File 'lib/yahns/chunk_body.rb', line 7

def initialize(body, vec)
  @body = body
  @vec = vec
end

Instance Method Details

#closeObject



25
26
27
# File 'lib/yahns/chunk_body.rb', line 25

def close
  @body.close if @body.respond_to?(:close)
end

#each {|"0\r\n\r\n".freeze| ... } ⇒ Object

Yields:

  • ("0\r\n\r\n".freeze)


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/yahns/chunk_body.rb', line 12

def each
  vec = @vec
  vec[2] = "\r\n".freeze
  @body.each do |chunk|
    vec[0] = "#{chunk.bytesize.to_s(16)}\r\n"
    vec[1] = chunk
    # vec[2] never changes: "\r\n" above
    yield vec
  end
  vec.clear
  yield "0\r\n\r\n".freeze
end