Class: YouTubeIt::GreedyChainIO

Inherits:
ChainIO
  • Object
show all
Defined in:
lib/youtube_it/chain_io.rb

Overview

Net::HTTP only can send chunks of 1024 bytes. This is very inefficient, so we have a spare IO that will send more when asked for 1024. We use delegation because the read call is recursive.

Constant Summary

BIG_CHUNK =

500 kb

512 * 1024

Instance Attribute Summary

Attributes inherited from ChainIO

#autoclose

Instance Method Summary (collapse)

Methods inherited from ChainIO

#expected_length

Constructor Details

- (GreedyChainIO) initialize(*with_ios)



62
63
64
# File 'lib/youtube_it/chain_io.rb', line 62

def initialize(*with_ios)
  __setobj__(YouTubeIt::ChainIO.new(with_ios))
end

Instance Method Details

- (Object) length



73
74
75
# File 'lib/youtube_it/chain_io.rb', line 73

def length()
  __getobj__.expected_length
end

- (Object) read(size = BIG_CHUNK, dst_buf = nil)



66
67
68
69
70
71
# File 'lib/youtube_it/chain_io.rb', line 66

def read(size = BIG_CHUNK, dst_buf = nil)
  src_buf = __getobj__.read(size)
  return nil unless src_buf
  copy_buf(src_buf, dst_buf) if dst_buf
  src_buf
end