# File lib/ldap/ldif.rb, line 437
    def LDIF.parse_file( file, sort=false ) # :yield: record

      File.open( file ) do |f|
        entries = []
        entry = false
        header = true
        version = false

        while line = f.gets

          if line =~ /^dn:/
            header = false

            if entry && ! version
              if block_given?
                yield parse_entry( entry )
              else
                entries << parse_entry( entry )
              end
            end

            if version
              entry << line
              version = false
            else
              entry = [ line ]
            end

            next
          end

          if header && line.downcase =~ /^version/
            entry = [ line ]
            version = true
            next
          end
        
          entry << line
        end

        if block_given?
          yield parse_entry( entry )
          nil
        else
          entries << parse_entry( entry )

          # Sort entries if sorting has been requested.
          entries.sort! { |x,y| x.dn.length <=> y.dn.length } if sort
          entries
        end

      end

    end