17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/webloc.rb', line 17
def self.load(filename)
raise FileNotFoundError, "File not found: #{filename}" unless File.exist?(filename)
begin
data = File.read(filename)
rescue => e
raise FileNotFoundError, "Unable to read file '#{filename}': #{e.message}"
end
raise EmptyFileError, "File is empty: #{filename}" if data.empty?
data = data.force_encoding('binary') rescue data
url = nil
if data !~ /\<plist/
url = parse_binary_format(data, filename)
else
url = parse_xml_format(filename)
end
raise CorruptedFileError, "No URL found in webloc file: #{filename}" if url.nil? || url.empty?
new(url)
end
|