lib/aviglitch/avi.rb in aviglitch-0.2.0 vs lib/aviglitch/avi.rb in aviglitch-0.2.2

- old
+ new

@@ -77,20 +77,26 @@ # List of indices for 'movi' data. attr_accessor :indices # Object which represents RIFF structure. attr_accessor :riff - attr_accessor :path, :movi #:nodoc: + attr_accessor :path, :movi, :tmpdir #:nodoc: protected :path, :path=, :movi, :movi= ## - # Generates an instance with the necessary structure from the +path+. + # Generates an instance. def initialize path = nil - return if path.nil? + return unless @movi.nil? # don't reconfigure the path when cloning + self.path = path unless path.nil? + end + + ## + # Set +path+ of the source file. + def path= path #:nodoc: @path = path File.open(path, 'rb') do |io| - @movi = Tempfile.new 'aviglitch', binmode: true + @movi = Tempfile.new 'aviglitch', @tmpdir, binmode: true @riff = [] @indices = [] @superidx = [] @was_avi2 = false io.rewind @@ -388,21 +394,22 @@ def inspect #:nodoc: "#<#{self.class.name}:#{sprintf("0x%x", object_id)} @movi=#{@movi.inspect}>" end def initialize_copy avi #:nodoc: - avi.path = @path.dup - md = Marshal.dump @indices - avi.indices = Marshal.load md - md = Marshal.dump @riff - avi.riff = Marshal.load md - newmovi = Tempfile.new 'aviglitch', binmode: true - movipos = @movi.pos - @movi.rewind - newmovi.print @movi.read - @movi.pos = movipos + md = Marshal.dump avi.indices + @indices = Marshal.load md + md = Marshal.dump avi.riff + @riff = Marshal.load md + newmovi = Tempfile.new 'aviglitch-clone', @tmpdir, binmode: true + movipos = avi.movi.pos + avi.movi.rewind + while d = avi.movi.read(BUFFER_SIZE) do + newmovi.print d + end + avi.movi.pos = movipos newmovi.rewind - avi.movi = newmovi + @movi = newmovi end def print_chunk io, chunk #:nodoc: offset = io.pos if chunk.is_list? \ No newline at end of file