Fix exception while writing utf8 to cache
This commit is contained in:
parent
517ff4bd76
commit
18ba6bea34
@ -9,6 +9,8 @@ module MusicBrainz
|
|||||||
end
|
end
|
||||||
|
|
||||||
def load(resource, query, params)
|
def load(resource, query, params)
|
||||||
|
raise Exception.new("You need to run MusicBrainz.configure before querying") if MusicBrainz.config.nil?
|
||||||
|
|
||||||
response = contents_of(build_url(resource, query))
|
response = contents_of(build_url(resource, query))
|
||||||
xml = Nokogiri::XML.parse(response).remove_namespaces!.xpath('/metadata')
|
xml = Nokogiri::XML.parse(response).remove_namespaces!.xpath('/metadata')
|
||||||
data = params[:binding].parse(xml)
|
data = params[:binding].parse(xml)
|
||||||
|
@ -18,12 +18,12 @@ module MusicBrainz
|
|||||||
response = nil
|
response = nil
|
||||||
|
|
||||||
if File.exist?(file_path)
|
if File.exist?(file_path)
|
||||||
response = File.open(file_path).gets
|
response = File.open(file_path, 'rb').gets
|
||||||
else
|
else
|
||||||
response = super
|
response = super
|
||||||
unless response.nil? or response.empty?
|
unless response.nil? or response.empty?
|
||||||
FileUtils.mkdir_p file_path.split('/')[0..-2].join('/')
|
FileUtils.mkdir_p file_path.split('/')[0..-2].join('/')
|
||||||
File.open(file_path, 'w') do |f|
|
File.open(file_path, 'wb') do |f|
|
||||||
f.puts response
|
f.puts response
|
||||||
f.chmod 0755
|
f.chmod 0755
|
||||||
f.close
|
f.close
|
||||||
|
Loading…
x
Reference in New Issue
Block a user