Sha256: 31b84810f36c215d0c66fa3864d9d4feb9c7715ff61a2b4905ac1df6c2f27938

Contents?: true

Size: 1018 Bytes

Versions: 4

Compression:

Stored size: 1018 Bytes

Contents

module FLV
  # FLV::File provide methods to read a FLV file easily.
  # Interface is similar to ::File, except that #each will
  # return FLV chunks instead of lines.
  module File
    def each(*arg, &block)
      return super unless arg.empty?
      return to_enum unless block_given?
      h= read(Header)
      yield h
      super(Tag, &block)
    end

    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

    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
    
    def self.foreach(portname, *, &block)
      open(portname) do |f|
        f.each(&block)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
marcandre-flvedit-0.6.2 lib/flv/file.rb
marcandre-flvedit-0.6.3 lib/flvedit/flv/file.rb
flvedit-0.6.3 lib/flvedit/flv/file.rb
flvedit-0.6.2 lib/flv/file.rb