Module: FLV::File

Defined in:
lib/flv/file.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.foreach(portname, &block) ⇒ Object



35
36
37
38
39
# File 'lib/flv/file.rb', line 35

def self.foreach(portname, *, &block)
  open(portname) do |f|
    f.each(&block)
  end
end

.open(*arg) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/flv/file.rb', line 11

def self.open(*arg)
  file = ::File.open(*arg)
  begin
    file = return_value = file.packed.extend(File)
  rescue Exception
    file.close
    raise
  end
  begin 
    return_value = yield(file) 
  ensure 
    file.close 
  end if block_given? 
  return_value 
end

.read(portname, *arg) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/flv/file.rb', line 27

def self.read(portname, *arg)
  open(portname) do |f|
    return f.to_a if arg.empty?
    n, offset = arg.first, arg[1] || 0
    f.each.first(n+offset)[offset, offset+n-1]
  end
end

Instance Method Details

#each(*arg) {|h| ... } ⇒ Object

Yields:

  • (h)


3
4
5
6
7
8
9
# File 'lib/flv/file.rb', line 3

def each(*arg, &block)
  return super unless arg.empty?
  return to_enum unless block_given?
  h= read(Header)
  yield h
  super(Tag, &block)
end