Module: FLV::File

Defined in:
lib/flvedit/flv/file.rb,
lib/flvedit/processor/base.rb

Overview

module Edit

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.foreach(portname, &block) ⇒ Object



38
39
40
41
42
# File 'lib/flvedit/flv/file.rb', line 38

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

.open(fn, mode = "rb") ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/flvedit/flv/file.rb', line 14

def self.open(fn, mode = "rb")
  file = ::File.open(fn, mode)
  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



30
31
32
33
34
35
36
# File 'lib/flvedit/flv/file.rb', line 30

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)


6
7
8
9
10
11
12
# File 'lib/flvedit/flv/file.rb', line 6

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

#each_sourceObject

A file acts as a single source, so…



87
88
89
# File 'lib/flvedit/processor/base.rb', line 87

def each_source
  yield
end